我知道有人会通过将probability=True
选项传递到构造函数中来评估sklearn.svm.SVC
的AUC,并让SVM预测概率,但我不确定如何评估sklearn.svm.LinearSVC
的AUC。有人知道怎么回事吗?
我想使用LinearSVC
超过SVC
,因为LinearSVC
似乎在具有许多属性的数据上训练得更快。
您可以使用CalibratedClassifierCV类来提取概率。下面是一个示例代码:
from sklearn.svm import LinearSVC
from sklearn.calibration import CalibratedClassifierCV
from sklearn import datasets
#Load iris dataset
iris = datasets.load_iris()
X = iris.data[:, :2] # Using only two features
y = iris.target #3 classes: 0, 1, 2
linear_svc = LinearSVC() #The base estimator
# This is the calibrated classifier which can give probabilistic classifier
calibrated_svc = CalibratedClassifierCV(linear_svc,
method='sigmoid', #sigmoid will use Platt's scaling. Refer to documentation for other methods.
cv=3)
calibrated_svc.fit(X, y)
# predict
prediction_data = [[2.3, 5],
[4, 7]]
predicted_probs = calibrated_svc.predict_proba(prediction_data) #important to use predict_proba
print predicted_probs
看起来是不可能的。https://github.com/scikit-learn/scikit-learn/issues/4820