使用scikitlearn的LinearSVC分类器时如何启用概率估计 [英] how to enable probability estimates when using scikitlearn's LinearSVC classifier

查看:480
本文介绍了使用scikitlearn的LinearSVC分类器时如何启用概率估计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以与sklearn.svm.SVCprobability=True选项相似的方式从sklearn.svm.LinearSVC模型获得预测的概率估计,因此我需要避免基础libsvm的二次拟合罚分我的训练集很大,因此SVC的数量.

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.

推荐答案

sklearn.svm.LinearSVC没有正确注意到的predict_proba方法.

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')

生成的svm模型确实具有predict_proba方法可用.

The resulting svm model indeed has predict_proba method available.

您可能会了解有关 CalibratedClassifierCV

这篇关于使用scikitlearn的LinearSVC分类器时如何启用概率估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆