Home | Develop | Download | Contact
example_logisticregression_ig2.cpp

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

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

Para executar o programa:

./example_logisticregression_ig2

Retornando por consola:

{X,Y}
2    6    1500 22   0    
4    6    1500 23   1    
2    6    1500 28   1    
2    6    1500 28   0    
4    6    1500 35   0    
4    6    1500 39   0    
2    6    1500 22   1    
2    6    1500 26   0    
2    6    1500 26   1    
2    6    1500 28   1    
2    6    1500 35   1    
4    6    1500 28   1    
4    6    1500 30   0    
4    6    1500 35   0    
4    6    1500 35   1    
4    6    1500 38   1    

    W_ig: 4.6454166929886   0                 0                 0                 -0.12066017384386 
 Cost(W): 0.078433225987246

    W_ig: 251.21391246223   -0.16324517096075 -0.16324517096075 -0.16324517096075 -0.16324517096075 
 Cost(W): 0.041120692117862

Código example_logisticregression_ig2.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Conf.Show=false; Conf.SetMinError(1e-07); Conf.SetAlpha(0.1);
// Generating data
Pds::Vector Y="0 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1";
Pds::Matrix X=
"2 4 2 2 4 4 2 2 2 2 2 4 4 4 4 4\n"
"6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n"
"1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 1500\n"
"22 23 28 28 35 39 22 26 26 28 35 28 30 35 35 38";
X=X.T();
Y=Y.T();
Pds::MergeHor({X,Y}).Print("{X,Y}\n");
Pds::Vector Yp;
Pds::Vector W;
std::cout<<"\n\n";
// Create W using training data
// Método ortogonal
W.T().Print(" W_ig: ");
std::cout<< " Cost(W): "<<Pds::LogisticModel::CostInformationGain(W,X,Y)<<"\n\n";
// Método de gradiente
//W=Pds::LogisticModel::GetW0MeanMethod(X);
W.T().Print(" W_ig: ");
std::cout<< " Cost(W): "<<Pds::LogisticModel::CostInformationGain(W,X,Y)<<"\n";
return 0;
}
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
bool SetAlpha(double Alpha)
Coloca el valor alpha.
bool SetMinError(double MinError)
Coloca el valor MinError.
Pds::Vector FittingGradientIG(Pds::IterationConf &Conf, const Pds::Matrix &X, const Pds::Vector &Y, const Pds::Vector &W0)
Calculo de pesos.
double CostInformationGain(const Pds::Vector &W, const Pds::Matrix &X, const Pds::Vector &Y)
Calculo de costo.
Pds::Vector Classify(const Pds::Vector &W, const Pds::Matrix &X)
Calculo del resultado del clasificador.
Pds::Vector FittingOrtogonalIG(const Pds::Matrix &X, const Pds::Vector &Y, unsigned int MinID)
Calculo de pesos.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed