Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SVM cross validation parameters optimisation and accuracy

I use the following code to train the svm using k-fold cross-validation but the prediction accuracy is low. What I am doing wrong and how to programmatically calculate the accuracy of the classifier using cross-validation.

Log.i(TAG,"Training..."); params.set_svm_type(CvSVM.C_SVC); params.set_kernel_type(CvSVM.RBF); params.set_C(1.0); params.set_degree(0.0); params.set_coef0(0.0); params.set_gamma(1.0); params.set_term_crit(new TermCriteria(TermCriteria.EPS, 10000, 1e-12));

    // k-fold cross validation
    int kFolds = 10;

    CvParamGrid C = new CvParamGrid();
    CvParamGrid p = new CvParamGrid();
    CvParamGrid nu = new CvParamGrid();
    CvParamGrid gamma = new CvParamGrid();
    CvParamGrid coeff = new CvParamGrid();
    CvParamGrid degree = new CvParamGrid();
    gamma.set_step(0.0);

    // initialize SVM object to avoid being Null object
    classifier = new CvSVM(trainingData, classes, new Mat(), new Mat(), params);

    classifier.train_auto(trainingData, classes, new Mat(), new Mat(), params, kFolds, C, gamma, p, nu, coeff, degree, false);

    classifier.save(XML.toString());
    Log.i(TAG,"Training Done & Trained Model Saved");