用需要概率估计的分数函数测试伪分类器

2024-04-20 01:51:40 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

^{pr2}$

如果我尝试对照评分函数测试这个虚拟分类器:

ml_macro_auc_s(dummy_clf, X, y)

scikit learn抱怨:

"ValueError: AUC is defined for binary classification only"

我尝试将probability=True传递给DummyClassifier,但它似乎接受了{a1}参数:

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

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

更新:

  • y是一个1D数组,其值在[0,1,2]范围内
  • X是一个特性数组,其行数与y和125列相同

Tags: the函数gttruelabels评分multilabel