对于多类分类任务,我必须获得Brier分数:
这是我的目标数组:
print(y_test.shape)
print(y_test.ndim)
(314,)
1
这是我预测的数组:
y_prob = svm.predict_proba(X_test)
print(y_prob.shape)
print(y_prob.ndim)
(314, 3)
2
考虑到这一点,我不能使用Sklearn的默认brier_score_loss,因为它会向我们抛出ValueError。
brier_score_loss(y_test, y_prob[:,1])
---------------------------------------------------------------------------
ValueError: Only binary classification is supported. Labels in y_true: [0. 1. 2.].
我还创建了一个自定义函数来计算多类别分类的Brier得分 [Wiki]。我在这里也得到了ValueError:
def multi_brier(targets, probs):
return np.mean(np.sum((probs - targets)**2))
# Calculate Brier Score
multi_brier(y_test, y_prob)
------------------------------------------------------------------------------
ValueError: operands could not be broadcast together with shapes (314,3) (314,)
如何处理此ValueError?帮助将不胜感激。谢谢!