Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Support Vector Regression prediction values

$
0
0
I am training a regression model to predict a label given a feature vector. Training and testing samples are drawn from 10 classes. I have trained SVM for regression as shown in the code below void train::trainSVR(Mat data, vector labels) { Ptr trainData = TrainData::create(data, ml::ROW_SAMPLE, labels); Ptr svr = SVM::create(); svr->setKernel(SVM::KernelTypes::POLY); svr->setType(SVM::Types::NU_SVR);//For n-class classification problem with imperfect class separation //svr->setC(5); //svr->setP(0.01); svr->setGamma(10.0);//for poly svr->setDegree(0.1);//for poly svr->setCoef0(0.0);//for poly svr->setNu(0.1); cout << "Training Support Vector Regressor..." << endl; //svr->trainAuto(trainData); svr->train(trainData); bool trained = svr->isTrained(); if (trained) { cout << "SVR Trained. Saving..." << endl; svr->save(".\\Trained Models\\SVR Model.xml"); cout << "SVR Model Saved." << endl; } } I have predicted my model as shown in the function below void train::predictSVR(Mat data, vector labels){ Mat_ output; vector predicted; //Create svm smart pointer and load trained model Ptr svr = Algorithm::load(".\\Trained Models\\SVR Model.xml"); ofstream prediction; prediction.open("SVR Prediction.csv", std::fstream::app);//open file for writing predictions in append mode for (int i = 0; i < labels.size(); i++) { float pred = svr->predict(data.row(i)); prediction << labels[i] << "," << pred << endl; } } The prediction gives me some value against every label. My questions are:- 1. What does the value against the label signify? 2. How do I retrieve Mean squared error (mse), support vectors and constants for the regression function `y=wx +b`. How do I get `b`, and `w` Kindly advice.

Viewing all articles
Browse latest Browse all 19555

Trending Articles