how to enable probability estimates when using scikitlearn's LinearSVC classifier

丶灬走出姿态 提交于 2020-01-24 00:44:14

问题


How can I get the probability estimates of predictions from a sklearn.svm.LinearSVC model in similar fashion to sklearn.svm.SVC's probability=True option that allows predict_proba() I need to avoid the quadratic fit penalty of the underlying libsvm of SVC as my training set is large.


回答1:


sklearn.svm.LinearSVC does not have predict_proba method as you noticed correctly.

However, you may try the following trick to circumvent this shortcoming:

from sklearn.svm import LinearSVC
from sklearn.calibration import CalibratedClassifierCV
svm = CalibratedClassifierCV(LinearSVC())
svm
CalibratedClassifierCV(base_estimator=LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True,
     intercept_scaling=1, loss='squared_hinge', max_iter=1000,
     multi_class='ovr', penalty='l2', random_state=None, tol=0.0001,
     verbose=0),
            cv=3, method='sigmoid')

The resulting svm model indeed has predict_proba method available.

You may read more about CalibratedClassifierCV



来源:https://stackoverflow.com/questions/54402210/how-to-enable-probability-estimates-when-using-scikitlearns-linearsvc-classifie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!