我正在按照此链接绘制多个类别的 ROC 曲线的文档:http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html
我对这一行特别感到困惑:
y_score = classifier.fit(X_train, y_train).decision_function(X_test)
我已经看到,在其他示例中, y_score 保存概率,并且它们都是正值,正如我们所期望的那样。然而,本例中的 y_score(A-C 类的每一列)大多为负值。有趣的是,它们加起来仍然是-1:
In: y_score[0:5,:]
Out: array([[-0.76305896, -0.36472635, 0.1239796 ],
[-0.20238399, -0.63148982, -0.16616656],
[ 0.11808492, -0.80262259, -0.32062486],
[-0.90750303, -0.1239792 , 0.02184016],
[-0.01108555, -0.27918155, -0.71882525]])
我该如何解释这一点?我如何仅从 y_score 判断模型对每个输入的预测是哪个类别?
编辑:所有相关代码:
import numpy as np
import matplotlib.pyplot as plt
from itertools import cycle
from sklearn import svm, datasets
from sklearn.metrics import roc_curve, auc
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import label_binarize
from sklearn.multiclass import OneVsRestClassifier
from scipy import interp
# Import some data to play with
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Binarize the output
y = label_binarize(y, classes=[0, 1, 2])
n_classes = y.shape[1]
# Add noisy features to make the problem harder
random_state = np.random.RandomState(0)
n_samples, n_features = X.shape
X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]
# shuffle and split training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
random_state=0)
# Learn to predict each class against the other
classifier = OneVsRestClassifier(svm.SVC(kernel='linear',
probability=True,
random_state=random_state))
y_score = classifier.fit(X_train, y_train).decision_function(X_test)