2

假设我定义了以下评分函数:

def multi_label_macro_auc(y_gt, y_pred):
    n_labels = y_pred.shape[1]
    auc_scores = [None] * n_labels

    # Convert the multi-class ground truth to a binary ground truth
    # by iterating through the labels
    for label in xrange(n_labels):
      auc_scores[label] =  roc_auc_score((y_gt == label)*1, y_pred[:,label])
    return np.mean(auc_scores)

ml_macro_auc_s   = make_scorer(multi_label_macro_auc, greater_is_better=True, 
                               needs_threshold=False, needs_proba=True)

我学习了DummyClassifier我的数据:

dummy_clf = DummyClassifier(strategy='stratified',random_state=0)
dummy_clf.fit(X,y)

如果我然后尝试根据我的评分函数测试这个虚拟分类器:

ml_macro_auc_s(dummy_clf, X, y)

scikit-learn 抱怨:

"ValueError: AUC is defined for binary classification only"

我尝试将 a 传递probability=TrueDummyClassifier,但它似乎接受该参数:

dummy_clf = DummyClassifier(strategy='stratified'',random_state=0, probability=True)

如何将需要软输出的自己的记分器应用到DummyClassifier?

更新:

  • y是一个一维数组,其值在范围内[0,1,2]
  • X是一个特征数组,其行数与 y 和125columns相同
4

0 回答 0