svc预测概率,使用scikitlearn的LinearSVC分类器时如何启用概率估计

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值