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)
{
Pds::Vector Yp;
unsigned int L=5000;
Pds::Matrix X;
Pds::Vector Y;
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");
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();
Metrics.
Print(
"\nCross validation metrics:\n");
Pds::Octave::Plot::PointsX2DYW( Dat.
Xcv,
W,
"testando.m",
"example_logisticregression_svm_training.png");
Metrics.
Print(
"\nTesting metrics:\n");
Pds::Octave::Plot::PointsX2DYW( Dat.
Xtt,
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.