0 votes
1 view
in Machine Learning by (15.5k points)

I use linear SVM from scikit learn (LinearSVC) for binary classification problems. I understand that LinearSVC can give me the predicted labels, and the decision scores but I wanted probability estimates (confidence in the label). I want to continue using LinearSVC because of speed (as compared to sklearn.svm.SVC with the linear kernel) Is it reasonable to use a logistic function to convert the decision scores to probabilities?

import sklearn.svm as suppmach

# Fit model:

svmmodel=suppmach.LinearSVC(penalty='l1',C=1)

predicted_test= svmmodel.predict(x_test)

predicted_test_scores= svmmodel.decision_function(x_test) 

I want to check if it makes sense to obtain Probability estimates simply as [1 / (1 + exp(-x)) ] where x is the decision score.

Alternately, are there other options wrt classifiers that I can use to do this efficiently?

Thanks.

1 Answer

0 votes
by (33.2k points)

You can simply use CalibratedClassifierCV from a scikit learn library, that can be used to solve this problem.

This method is used to add probability output to LinearSVC and many other classifiers, which uses the desicion_function method.

For example:

 svm = LinearSVC()

 clf = CalibratedClassifierCV(svm) 

 clf.fit(X_train, y_train)

 y_proba = clf.predict_proba(X_test)

Hope this answer helps.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...