使用scikitlearn的LinearSVC分类器时如何启用概率估计 [英] how to enable probability estimates when using scikitlearn's LinearSVC classifier
问题描述
如何以与sklearn.svm.SVC
的probability=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屋!