Home | Develop | Download | Contact
example_logisticregression_svm.cpp

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

g++ -static -o example_logisticregression_svm example_logisticregression_svm.cpp -lpdsnnmm

Para executar o programa:

./example_logisticregression_svm

Retornando por consola:

-------------------------
   IterationConf data    
-------------------------
    Alpha: 0.1
   Lambda: 0
 MinError: 1e-07
  MaxIter: 1000
-------------------------
iter:    272 Alpha: 2.0954e-07 last_error: 9.98646e-08   
-------------------------
    Alpha: 2.0954e-07
LastError: 9.98646e-08
 LastIter: 272
-------------------------
W:
0.058782905826334       0.85851292017232        0.85266113485321
Elapsed time: 12.060906 s
    
-----------------------------
 ClassificationMetrics data  
-----------------------------
Threshold       : 0.51
Samples         : 40000
----------------:------------
Pred.[0]/Act.[*]: 19544 0
Pred.[1]/Act.[*]: 457   19999
----------------:------------
Accuracy        : 98.86%
Precision       : 97.77%
Recall          : 100%
----------------:------------
FScore          : 98.87%
-----------------------------
    
-----------------------------
 ClassificationMetrics data  
-----------------------------
Threshold       : 0.51
Samples         : 40000
----------------:------------
Pred.[0]/Act.[*]: 19419 0
Pred.[1]/Act.[*]: 434   20147
----------------:------------
Accuracy        : 98.91%
Precision       : 97.89%
Recall          : 100%
----------------:------------
FScore          : 98.93%
-----------------------------

Código example_logisticregression_svm.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::IterationConf Conf; Conf.Show=true; Conf.SetMinError(1e-07);
Pds::Vector Yp;
// Generating data
unsigned int L=100000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Vector W(X.Ncol()+1);
// Split data set in {Training,Cross-validation,Test}
// Create W using training data
W.Fill(0.1); Conf.SetAlpha(0.1);
Pds::Ra::Tic();
W.T().Print("W:\n");
Pds::Ra::Toc();
// Testing W with testing data set
// Metrics
Metrics.Print("\n");
// Testing W with testing data set
Metrics.Print("\n");
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....
static Pds::ClassificationMetrics Calculate(double Threshold, const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto de tipo Pds::ClassificationMetrics.
static Pds::ClassificationMetrics Optimal(const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto 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.
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}.
void LoadDataLine(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por una linea.
Pds::Vector FittingGradientSVM(Pds::IterationConf &Conf, const Pds::Matrix &X, const Pds::Vector &Y, const Pds::Vector &W0)
Gradiente descendente para sigmoide.
Pds::Vector Classify(const Pds::Vector &W, const Pds::Matrix &X)
Calculo del resultado del clasificador.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed