Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why do not the parameter values ​change using the trainAuto () function of the SVM class of OpenCV 3.4?

OpenCV says that trainAuto() function trains an SVM with optimal parameters. Every time I train with trainAuto(), the parameters that are obtained are the same. According to this, the values ​​of the parameters should change if, for example, I change the value of kFold.

I tried to change the values ​​of kFold but I still get the same values ​​in the parameters.

The code I am using is the following:

SVM svm = SVM.create(); svm.setType(SVM.C_SVC); svm.setKernel(SVM.SIGMOID);

ParamGrid cgrid = ParamGrid.create(); ParamGrid gammaGrid = ParamGrid.create(); ParamGrid pGrid = ParamGrid.create(); ParamGrid nuGrid = ParamGrid.create(); ParamGrid coeffGrid = ParamGrid.create(); ParamGrid degreeGrid = ParamGrid.create();

int kFold = 10;
svm.trainAuto(train, Ml.ROW_SAMPLE, labels, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, false);

double C = svm.getC(); double gamma = svm.getGamma(); double P = svm.getP(); double Nu = svm.getNu(); double Coef0 = svm.getCoef0(); double Degree = svm.getDegree();

System.out.println("C: " +C); System.out.println("Gamma: " +gamma); System.out.println("P: " +P); System.out.println("Nu: " +Nu); System.out.println("Coeff: " +Coef0); System.out.println("Degree: " +Degree); The results that I always get are the following:

C: 1.0 Gamma: 1.0 P: 0.0 Nu: 0.0 Coeff: 0.0 Degree: 0.0

What am I doing wrong?

Why do not the parameter values ​change using the trainAuto () function of the SVM class of OpenCV 3.4?

OpenCV says that trainAuto() function trains an SVM with optimal parameters. Every time I train with trainAuto(), the parameters that are obtained are the same. According to this, the values ​​of the parameters should change if, for example, I change the value of kFold.

I tried to change the values ​​of kFold but I still get the same values ​​in the parameters.

The code I am using is the following:

SVM svm = SVM.create(); svm.setType(SVM.C_SVC); SVM.create();

svm.setType(SVM.C_SVC);

svm.setKernel(SVM.SIGMOID);

ParamGrid cgrid = ParamGrid.create(); ParamGrid.create();

ParamGrid gammaGrid = ParamGrid.create(); ParamGrid.create();

ParamGrid pGrid = ParamGrid.create(); ParamGrid.create();

ParamGrid nuGrid = ParamGrid.create(); ParamGrid.create();

ParamGrid coeffGrid = ParamGrid.create(); ParamGrid.create();

ParamGrid degreeGrid = ParamGrid.create();

ParamGrid.create();

int kFold = 10;
10;

svm.trainAuto(train, Ml.ROW_SAMPLE, labels, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, false);

double C = svm.getC(); svm.getC();

double gamma = svm.getGamma(); svm.getGamma();

double P = svm.getP(); svm.getP();

double Nu = svm.getNu(); svm.getNu();

double Coef0 = svm.getCoef0(); svm.getCoef0();

double Degree = svm.getDegree();

System.out.println("C: " +C); +C);

System.out.println("Gamma: " +gamma); +gamma);

System.out.println("P: " +P); +P);

System.out.println("Nu: " +Nu); +Nu);

System.out.println("Coeff: " +Coef0); +Coef0);

System.out.println("Degree: " +Degree); +Degree);

The results that I always get are the following:

C: 1.0 Gamma: 1.0 P: 0.0 Nu: 0.0 Coeff: 0.0 Degree: 0.00.0

What am I doing wrong?