Home | Develop | Download | Contact
example_kmeansnn.cpp

Programa para el testeo de las funciones.Para compilar o código example_kmeansnn.cpp:

g++ -static -o example_kmeansnn example_kmeansnn.cpp -lpdsmlmm -lpdsramm -lpdsspmm

Para executar o programa:

./example_kmeansnn

Retornando por consola:

Working Kmeans over ID: 0
┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 22          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 6.5e-05     │
└──────────────────────────────┘

Working Kmeans over ID: 1
┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 23          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 6.3e-05     │
└──────────────────────────────┘

Metrics of training:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 1000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 485     12      ║
║ Pred.[1]/Act.[*]: 15      488     ║
╠═══════════════════════════════════╣
║         Accuracy: 97.3  %         ║
║        Precision: 97.02 %         ║
║           Recall: 97.6  %         ║
╠═══════════════════════════════════╣
║           FScore: 97.31 %         ║
╚═══════════════════════════════════╝

Metrics of testing:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 1000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 472     17      ║
║ Pred.[1]/Act.[*]: 28      483     ║
╠═══════════════════════════════════╣
║         Accuracy: 95.5  %         ║
║        Precision: 94.52 %         ║
║           Recall: 96.6  %         ║
╠═══════════════════════════════════╣
║           FScore: 95.55 %         ║
╚═══════════════════════════════════╝
Classification - data


Classification - training


Classification - testing

Código example_kmeansnn.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Conf.SetMaxIter(10000); Conf.Show=true;
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
unsigned int K=5; // Number of clusters
unsigned int L=1000; // Numer of 1s or 0s
Pds::Matrix X;
Pds::Vector Y,Yp;
// Generating training data
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_kmeansnn_data.png");
/********* Training *********/
// Create KmeansNn
Pds::KmeansNn KmNn(Conf,X,Y,K);
// Predict "training" data with Knn=7
Yp=KmNn.Predict(X,7);
// Metrics of training
Metrics.Print("\nMetrics of training:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_kmeansnn_training.png");
/********* Testing *********/
// Generating testing data
// Predict testing data with Knn=7
Yp=KmNn.Predict(X,7);
// Metrics testing
Metrics.Print("\nMetrics of testing:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_kmeansnn_testing.png");
return 0;
}
La clase tipo Pds::ClassificationMetrics . Esta clase genera un bloque de datos para analizar curvas ...
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
La clase tipo Pds::KmeansNn . Esta clase genera una estructura de Pds::KmeansNn. Para usar incluir Pd...
Definition: KmeansNn.hpp:67
static Pds::ClassificationMetrics Calculate(double Threshold, const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto Dat de tipo Pds::ClassificationMetrics.
void Print(std::string str="")
Imprime en pantalla los datos de la estructura tipo Pds::ClassificationMetrics.
bool SetMaxIter(unsigned int MaxIter)
Coloca el valor MaxIter.
double Predict(const Pds::Vector &x, unsigned int Knn) const
Evalua el objeto de tipo Pds::KmeansNn.
void LoadDataYinYang(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por mas de una curva.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed