为什么不使用OpenCV 3.4的SVM类的trainAuto()函数更改参数值?

时间:2019-07-10 23:34:05

标签: java opencv machine-learning computer-vision svm

OpenCV表示trainAuto()函数训练具有最佳参数的SVM。 每次我使用trainAuto()进行训练时,获得的参数都是相同的。据此,例如,如果我更改kFold的值,则应更改参数的值。

我试图更改kFold的值,但在参数中我仍然得到相同的值。

我正在使用的代码如下:

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);

我总是得到的结果如下:

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

我在做什么错了?

0 个答案:

没有答案