Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Support Vector Regression prediction values

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<int> labels)
{
    Ptr<TrainData> trainData = TrainData::create(data, ml::ROW_SAMPLE, labels);
    Ptr<SVM> 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<int> labels){
    Mat_ <float> output;
    vector<int> predicted;
    //Create svm smart pointer and load trained model
    Ptr<ml::SVM> svr = Algorithm::load<ml::SVM>(".\\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.