SVM中的置信度或概率

时间:2015-07-21 09:09:13

标签: matlab opencv svm emgucv libsvm

我在EmguCV中使用多类SVM分类器。我需要每个班级的SVM置信度。例如,我不需要SVM只声明类号,我需要它告诉我不同​​类的P(classnumbers | input)。 如何在EmguCV中获得此概率或分数?(多级)

如果没有办法,matlab中的多类SVM分类器是否有任何解决方案?

1 个答案:

答案 0 :(得分:0)

我不熟悉EmguCV,但在OpenCV中您可以执行此类操作以获取SVM中的概率:

CvSVM svm;   // declare your classifier;
// then do your training process here
svm.train(featuresToBeTrained, labelsToBeTrained, cv::Mat(), cv::Mat(), params); // params are the svm parameters, you can use libsvm to optimize them.
//libsvm website: https://www.csie.ntu.edu.tw/~cjlin/libsvm/

// perform prediction
double confidenceScore = svm.predict(featuresToBePredected, true); // this will give you a signed distance to the margin.

// Then you can normalize the score to improve it, one best way is to use sigmoid function.
double finalScore = sigmoidFunc(confidenceScore, sigmoidA, sigmoidB); // sigmoidA and sigmoidB are params for sigmoid function, take wikipedia for reference

// You can define sigmoid function like this    
double sigmoidFunc(double confidenceScore, double A, double B)
{
    double fApB = confidenceScore*A + B;
    // 1-p used later; avoid catastrophic cancellation
    if (fApB >= 0)
    {
        return 1.0 - (exp(-fApB) / (1.0 + exp(-fApB)));
    }
    else
    {
        return 1.0 - (1.0 / (1.0 + exp(fApB)));
    }
}

希望它有所帮助!

<强>更新

对于多类案例,请参考以下链接:
click here