Home | Develop | Download | Contact
example_kmeansperceptron.cpp

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

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

Para executar o programa:

./example_kmeansperceptron

Retornando por consola:

┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 42          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 0.001047    │
└──────────────────────────────┘
┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 33          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 0.000635    │
└──────────────────────────────┘
Trained cluster 39 of 39 with 184 samples.        

Metrics of training:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 8000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 3856    113     ║
║ Pred.[1]/Act.[*]: 144     3887    ║
╠═══════════════════════════════════╣
║         Accuracy: 96.79 %         ║
║        Precision: 96.43 %         ║
║           Recall: 97.17 %         ║
╠═══════════════════════════════════╣
║           FScore: 96.8  %         ║
╚═══════════════════════════════════╝

Metrics of testing:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 8000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 3811    116     ║
║ Pred.[1]/Act.[*]: 189     3884    ║
╠═══════════════════════════════════╣
║         Accuracy: 96.19 %         ║
║        Precision: 95.36 %         ║
║           Recall: 97.1  %         ║
╠═══════════════════════════════════╣
║           FScore: 96.22 %         ║
╚═══════════════════════════════════╝
Classification - data


Classification - training


Classification - testing

Código example_kmeansperceptron.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=40; // Number of clusters
unsigned int L=4000; // Numer of 1s or 0s
Pds::Matrix X;
Pds::Vector Y;
Pds::Vector Yp;
/********* Training *********/
// Generating training data
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_kmeansperceptron_data.png");
// Create and training an KmeansPerceptron
Pds::KmeansPerceptron KP(Conf,X,Y,K);
// Predict training data
Yp=KP.Predict(X);
// Metrics of training
Metrics.Print("\nMetrics of training:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_kmeansperceptron_training.png");
/********* Testing *********/
// Generating testing data
// Predict testing data
Yp=KP.Predict(X);
// Metrics testing
Metrics.Print("\nMetrics of testing:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_kmeansperceptron_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::KmeansPerceptron . Esta clase genera una matriz de Nlin lineas y 1 columna....
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) const
Evalua el objeto de tipo Pds::KmeansPerceptron.
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