Scikit-learn predict_proba gives wrong answers
predict_probas
is using the Platt scaling feature of libsvm to callibrate probabilities, see:
- How does sklearn.svm.svc's function predict_proba() work internally?
So indeed the hyperplane predictions and the proba calibration can disagree, especially if you only have 2 samples in your dataset. It's weird that the internal cross validation done by libsvm for scaling the probabilities does not fail (explicitly) in this case. Maybe this is a bug. One would have to dive into the Platt scaling code of libsvm to understand what's happening.
if you use svm.LinearSVC()
as estimator, and .decision_function()
(which is like svm.SVC's .predict_proba()) for sorting the results from most probable class to the least probable one. this agrees with .predict()
function. Plus, this estimator is faster and gives almost the same results with svm.SVC()
the only drawback for you might be that .decision_function()
gives a signed value sth like between -1 and 3 instead of a probability value. but it agrees with the prediction.