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 -lpdsmlmm -lpdsramm -lpdsspmm

Para executar o programa:

./example_logisticregression_svm

Retornando por consola:

W:
0.87571855488965        0.62273771996737        0.38476281677595
┌──────────────────────────────┐
│    SVM                       │
│    IterationConf init data   │
├──────────────────────────────┤
│           Alpha: 0.1         │
│          Lambda: 0           │
│   MinError ΔW/W: 1.0000e-07  │
│         MaxIter: 1000        │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 1000        │
│           Alpha: 0.001       │
│  LastError ΔW/W: 2.2834e-04  │
│ Cost Func Error: 5.8753e-01  │
└──────────────────────────────┘
┌──────────────────────────────┐
│    SVM                       │
│    IterationConf end data    │
├──────────────────────────────┤
│           Alpha: 0.001       │
│  LastError ΔW/W: 2.2834e-04  │
│        LastIter: 1000        │
└──────────────────────────────┘
W:
0.15017888674738        1.2521817273226 1.1310944900835
Elapsed time: 6.716934 s

Cross validation metrics:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.53            ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 940     13      ║
║ Pred.[1]/Act.[*]: 31      1016    ║
╠═══════════════════════════════════╣
║         Accuracy: 97.8  %         ║
║        Precision: 97.04 %         ║
║           Recall: 98.74 %         ║
╠═══════════════════════════════════╣
║           FScore: 97.88 %         ║
╚═══════════════════════════════════╝

Testing metrics:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.53            ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 995     12      ║
║ Pred.[1]/Act.[*]: 34      959     ║
╠═══════════════════════════════════╣
║         Accuracy: 97.7  %         ║
║        Precision: 96.58 %         ║
║           Recall: 98.76 %         ║
╠═══════════════════════════════════╣
║           FScore: 97.66 %         ║
╚═══════════════════════════════════╝
Classification - data


Classification - training


Classification - testing

Código example_logisticregression_svm.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Conf.Show=true; Conf.SetMinError(1e-06);
Conf.SetAlpha(0.1); Conf.SetMaxIter(4000); Conf.SetAlphaSmart(true);
Conf.SetLambda(0.1);
Pds::Vector Yp;
// Generating data
unsigned int L=5000;
Pds::Matrix X;
Pds::Vector Y;
// Split data set in {Training,Cross-validation,Test}
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DY(Dat.Xtr,Dat.Ytr,"testando.m","example_logisticregression_svm_data.png");
// Create W using training data
Pds::Vector W(X.Ncol()+1);
W.Set(0,2);W.Set(1,-2);W.Set(2,3);
W.T().Print("W:\n");
Pds::Ra::Tic();
W.T().Print("W:\n");
Pds::Ra::Toc();
// Testing W with testing data set
// Metrics
Metrics.Print("\nCross validation metrics:\n");
Pds::Octave::Plot::PointsX2DYW( Dat.Xcv,
Dat.Ycv,
W,
"testando.m",
"example_logisticregression_svm_training.png");
// Testing W with testing data set
Metrics.Print("\nTesting metrics:\n");
Pds::Octave::Plot::PointsX2DYW( Dat.Xtt,
Dat.Ytt,
W,
"testando.m",
"example_logisticregression_svm_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....
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 SetLambda(double Lambda)
Coloca el valor lambda.
bool SetAlphaSmart(bool AlphaSmart)
Establece el valor AlphaSmart.
bool SetAlpha(double Alpha)
Coloca el valor alpha.
bool SetMaxIter(unsigned int MaxIter)
Coloca el valor MaxIter.
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}, selecionados aleatoriamente sin ...
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