1

In LIBSVM, the -b flag in svmtrainis used to enable training a SVC or SVR model for probability estimates. To get the corresponding results for the test set, we also set the -b results in svmpredict

For example, in MATLAB, we would write the following code to train and test with probability estimates enabled:

model = svmtrain(train_labels, train_set, '-b 1')
[result, accuracy, prob] = svmpredict(test_labels, test_set, '-b 1')

However, when initializing the SVC in the scikit-learn library, we can only set the -b flag when training, which would be the same as setting the -b flag on svmtrain:

clf = scikit.svm.SVC(probability=True)

For testing in scikit-learn, I am using clf.predict(test_set) to get the classes. However, this yields different results then when I use svmpredict with -b 1 flag.

What is the equivalent in scikit-learn svm for setting the -b flag during testing with svmpredict?

aad
  • 98
  • 7
  • Yes, its expected because predict() doesnt use the probability. Its mentioned in the docs here: scikit-learn.org/dev/modules/svm.html#scores-and-probabilities – Vivek Kumar Jan 10 '18 at 05:31

1 Answers1

-1

Scikit-learn doesn't use a flag to predict the probabilities of a classifier, there's an additional function available called .predict_proba. Have a look at the documentation.

The probabilities are determined using Platt scaling, which is a way to combine arbitrary outputs from a classifier into class probabilities.

See also the answer here: How does sklearn.svm.svc's function predict_proba() work internally?

Archie
  • 2,247
  • 1
  • 18
  • 35