Home | Develop | Download | Contact
example_decisiontree.cpp

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

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

Para executar o programa:

./example_decisiontree

Retornando por consola:

Pds::DecisionTree::Counter: 43

Training metrics:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 980     22      ║
║ Pred.[1]/Act.[*]: 20      978     ║
╠═══════════════════════════════════╣
║         Accuracy: 97.9  %         ║
║        Precision: 98    %         ║
║           Recall: 97.8  %         ║
╠═══════════════════════════════════╣
║           FScore: 97.9  %         ║
╚═══════════════════════════════════╝

Testing metrics:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 970     35      ║
║ Pred.[1]/Act.[*]: 30      965     ║
╠═══════════════════════════════════╣
║         Accuracy: 96.75 %         ║
║        Precision: 96.98 %         ║
║           Recall: 96.5  %         ║
╠═══════════════════════════════════╣
║           FScore: 96.74 %         ║
╚═══════════════════════════════════╝
example_decisiontree_data.png


example_decisiontree_training.png


example_decisiontree_testing.png

Código example_decisiontree.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::Octave::Colormap="jet";
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Conf.Show=false; Conf.SetMinError(1e-07); Conf.SetAlpha(0.1);
Pds::Vector Yp;
// =========================================================================
// Load training data
Pds::Matrix X(Pds::Ra::TextFormat,"../test/dataset/data_x_yinyang.txt");
Pds::Vector Y(Pds::Ra::TextFormat,"../test/dataset/data_y_yinyang.txt");
//Pds::Matrix X(Pds::Ra::TextFormat,"../test/dataset/data_hard14_x.txt");
//Pds::Vector Y(Pds::Ra::TextFormat,"../test/dataset/data_hard14_y.txt");
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_decisiontree_data.png");
// =========================================================================
// Creando un arbol
Pds::DecisionTree Arbol("k2means",Conf,X,Y,0.99,2);
std::cout<<"Pds::DecisionTree::Counter: "<<Pds::DecisionTree::Counter<<std::endl;
// Exportando arbol en archivo en formato dot.
Arbol.ExportDotFile("arbol.dot");
// Predict training data
Yp=Arbol.Predict(X);
// Metrics of training
Metrics.Print("\nTraining metrics:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_decisiontree_training.png");
// =========================================================================
// Load testing data
Pds::Matrix Xtt(Pds::Ra::TextFormat,"../test/dataset/data_x_yinyang_test.txt");
Pds::Vector Ytt(Pds::Ra::TextFormat,"../test/dataset/data_y_yinyang_test.txt");
//Pds::Matrix Xtt(Pds::Ra::TextFormat,"../test/dataset/data_hard14_x.txt");
//Pds::Vector Ytt(Pds::Ra::TextFormat,"../test/dataset/data_hard14_y.txt");
// Predict testing data
Yp=Arbol.Predict(Xtt);
// Metrics of testing
Metrics.Print("\nTesting metrics:\n");
Pds::Octave::Plot::PointsX2DY(Xtt,Yp,"testando.m","example_decisiontree_testing.png");
return 0;
}
La clase tipo Pds::ClassificationMetrics . Esta clase genera un bloque de datos para analizar curvas ...
La clase tipo Pds::DecisionTree . Esta clase genera un arbol de decision para unos datos dados....
static unsigned int Counter
La clase tipo Pds::IterationConf . 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.
double Predict(const Pds::Vector &x) const
Evalua el objeto de tipo Pds::DecisionTree.
bool ExportDotFile(const std::string &filename) const
Salva en formato .dot el objeto de tipo Pds::DecisionTree.
bool SetAlpha(double Alpha)
Coloca el valor alpha.
bool SetMinError(double MinError)
Coloca el valor MinError.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed