Programa para el testeo de las funciones.Para compilar o código example_perceptron_predict.cpp:
g++ -static -o example_perceptron_predict example_perceptron_predict.cpp -lpdsmlmm -lpdsramm -lpdsspmm
Para executar o programa:
./example_perceptron_predict
Retornando por consola:
Elapsed time: 1.862 ms
Neurona:
-0.055853392180644 4.545875006622 4.5637016611478
Training:
╔═══════════════════════════════════╗
║ ClassificationMetrics data ║
╠═══════════════════════════════════╣
║ Threshold: 0.5 ║
║ Samples: 2400 ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 1229 12 ║
║ Pred.[1]/Act.[*]: 0 1159 ║
╠═══════════════════════════════════╣
║ Accuracy: 99.5 % ║
║ Precision: 100 % ║
║ Recall: 98.98 % ║
╠═══════════════════════════════════╣
║ FScore: 99.48 % ║
╚═══════════════════════════════════╝
Cross-validation:
╔═══════════════════════════════════╗
║ ClassificationMetrics data ║
╠═══════════════════════════════════╣
║ Threshold: 0.49 ║
║ Samples: 800 ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 389 0 ║
║ Pred.[1]/Act.[*]: 0 411 ║
╠═══════════════════════════════════╣
║ Accuracy: 100 % ║
║ Precision: 100 % ║
║ Recall: 100 % ║
╠═══════════════════════════════════╣
║ FScore: 100 % ║
╚═══════════════════════════════════╝
Elapsed time: 20.41 ms
Testing:
╔═══════════════════════════════════╗
║ ClassificationMetrics data ║
╠═══════════════════════════════════╣
║ Threshold: 0.49 ║
║ Samples: 800 ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 382 0 ║
║ Pred.[1]/Act.[*]: 0 418 ║
╠═══════════════════════════════════╣
║ Accuracy: 100 % ║
║ Precision: 100 % ║
║ Recall: 100 % ║
╠═══════════════════════════════════╣
║ FScore: 100 % ║
╚═══════════════════════════════════╝
Classification - training
Classification - testing
Código example_perceptron_predict.cpp:
#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::Vector Yp;
unsigned int L=2000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Ra::Tic();
Pds::Ra::Toc();
Pds::Vector W=Neurona.
GetW();
Neurona.
Print(
"\nNeurona:\n");
Metrics.
Print(
"\nTraining:\n");
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DYW(Dat.
Xtr,Dat.
Ytr,W,
"testando.m",
"example_perceptron_predict_training.png");
Pds::Ra::Tic();
Metrics.
Print(
"\nCross-validation:\n");
Pds::Ra::Toc();
Metrics.
Print(
"\nTesting:\n");
Pds::Octave::Plot::PointsX2DYW(Dat.
Xtt,Dat.
Ytt,W,
"testando.m",
"example_perceptron_predict_testing.png");
return 0;
}
La clase tipo Pds::ClassificationMetrics . Esta clase genera un bloque de datos para analizar curvas ...
La clase tipo Pds::DataSetBlock . Esta clase genera un bloque de datos para analizar curvas de aprend...
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
La clase tipo Pds::Perceptron . 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.
static Pds::ClassificationMetrics Optimal(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.
Pds::DataSetBlock Split(const Pds::Matrix &X, const Pds::Vector &Y, double Training, double CrossVal, double Test)
Divide un data set en 3 data set: {Training, CrossValidation, Test}, selecionados aleatoriamente sin ...
void LoadDataLine(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por una linea.
double Predict(const std::initializer_list< double > list) const
Evalua el objeto de tipo Pds::Perceptron.
const Pds::Vector & GetW(void) const
Retorna el vector de pesos.
void Print(std::string str="") const
Imprime en pantalla el contenido del vector de pesos después del texto indicado en str.