1

我知道可以sklearn.svm.SVC通过将probability=True选项传入构造函数并让 SVM 预测概率来评估 AUC,但我不确定如何评估sklearn.svm.LinearSVCAUC。有谁知道怎么做?

我想使用LinearSVCover,SVC因为LinearSVC似乎在具有许多属性的数据上训练得更快。

4

2 回答 2

1

您可以使用 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
于 2018-05-24T12:09:18.657 回答
0

看起来是不可能的。 https://github.com/scikit-learn/scikit-learn/issues/4820

于 2015-06-05T16:16:02.437 回答