Home | Develop | Download | Contact
example_decisiontree.cpp
1 
60 #include <iostream>
61 #include <Pds/Ra>
62 #include <Pds/Ml>
63 
64 int main(void)
65 {
66  Pds::Octave::Colormap="jet";
67  Pds::Octave::XLabel="x_1";
68  Pds::Octave::YLabel="x_2";
69 
71 
72  Pds::IterationConf Conf;
73  Conf.Show=false; Conf.SetMinError(1e-07); Conf.SetAlpha(0.1);
74 
75  Pds::Vector Yp;
76 
77  // =========================================================================
78  // Load training data
79  Pds::Matrix X(Pds::Ra::TextFormat,"../test/dataset/data_x_yinyang.txt");
80  Pds::Vector Y(Pds::Ra::TextFormat,"../test/dataset/data_y_yinyang.txt");
81  //Pds::Matrix X(Pds::Ra::TextFormat,"../test/dataset/data_hard14_x.txt");
82  //Pds::Vector Y(Pds::Ra::TextFormat,"../test/dataset/data_hard14_y.txt");
83 
84  Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_decisiontree_data.png");
85 
86  // =========================================================================
87  // Creando un arbol
89  Pds::DecisionTree Arbol("k2means",Conf,X,Y,0.99,2);
90  std::cout<<"Pds::DecisionTree::Counter: "<<Pds::DecisionTree::Counter<<std::endl;
91 
92  // Exportando arbol en archivo en formato dot.
93  Arbol.ExportDotFile("arbol.dot");
94 
95  // Predict training data
96  Yp=Arbol.Predict(X);
97 
98  // Metrics of training
99  Metrics = Pds::ClassificationMetrics::Calculate(0.5,Yp,Y);
100  Metrics.Print("\nTraining metrics:\n");
101 
102  Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_decisiontree_training.png");
103 
104  // =========================================================================
105  // Load testing data
106  Pds::Matrix Xtt(Pds::Ra::TextFormat,"../test/dataset/data_x_yinyang_test.txt");
107  Pds::Vector Ytt(Pds::Ra::TextFormat,"../test/dataset/data_y_yinyang_test.txt");
108  //Pds::Matrix Xtt(Pds::Ra::TextFormat,"../test/dataset/data_hard14_x.txt");
109  //Pds::Vector Ytt(Pds::Ra::TextFormat,"../test/dataset/data_hard14_y.txt");
110 
111  // Predict testing data
112  Yp=Arbol.Predict(Xtt);
113 
114  // Metrics of testing
115  Metrics = Pds::ClassificationMetrics::Calculate(0.5,Yp,Ytt);
116  Metrics.Print("\nTesting metrics:\n");
117 
118  Pds::Octave::Plot::PointsX2DY(Xtt,Yp,"testando.m","example_decisiontree_testing.png");
119 
120  return 0;
121 }
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.
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