【发布时间】:2020-01-24 07:44:02
【问题描述】:
尝试使用 SVM 绘制具有 1200 列(作为特征)的大小为 1200 的数据集的 ROC 曲线会出现以下错误:
'数组索引过多'
代码:
from sklearn.svm import SVC
svclassifier = SVC(kernel='linear')
svm = svclassifier.fit(X_train, Y_train).decision_function(X_test)
Y_pred = svclassifier.predict(X_test)
ns_predt = [0 for _ in range(len(Y_test))]
Y_predt = Y_pred[:,1]
Traceback (most recent call last) IndexError
<ipython-input-92-62de12967d46> in <module>
----> 1 Y_predt = Y_pred[:,1]
IndexError: too many indices for array
【问题讨论】:
-
显示工作代码,以便能够重现错误
-
Y_pred 的形状与您预期的不同,这就是您的 Y_pred[:,1] 不起作用的原因。你能打印“Y_pred.shape”吗?
-
Y_test 是 480 个实例的 0,1 个标签。 Y_test.shape 和 Y_pred.shape 给出的输出为 (480,0), (480,0).Y_pred 根据上面的代码给出的输出如下: [0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 0 1 0 0 ........ 1 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0]。 @ZarakiKenpachi
-
Y_pred.shape 是 (480,0) @Rens
标签: python size one-hot-encoding indices