I'm using libsvm to classify my dataset but I'm not reaching good results with SVM. I think that it is because the parameters: Gamma and Cost were defined wrongly. I'm training the SVM with C-SVC and RBF Kernel.Please tell how to obtain optimal parameters using a grid-search with 5-fold cross-validation process. My complete code is given below
int main(int,char **) { Ptr<ml::traindata> tdata = ml::TrainData::loadFromCSV("/home/vidushi/Desktop/new/vidtrain.csv",1,-2,0); Mat data = tdata->getTrainSamples(); int labels[38] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1}; Mat labelsMat(38, 1, CV_32SC1, labels); Ptr<cv::ml::svm> svm = cv::ml::SVM::create(); svm->setType(SVM::C_SVC); svm->setKernel(SVM::RBF); svm->setC(1000); svm->setGamma(100); Ptr<ml::traindata> td = ml::TrainData::create(data, ROW_SAMPLE, labelsMat); svm->trainAuto(td); Ptr<ml::traindata> tdata1 = ml::TrainData::loadFromCSV("/home/vidushi/Desktop/new/vidtest1.csv",1,-2,0); Mat data1 = tdata1->getTrainSamples(); Mat result; svm->predict(data1,result); cout<<result.rows<<" "<<result.cols<<"\n";="" cout<<"result="<< " "="" <<result<<"\n";="" return="" 0;="" }<="" p="">