machine-learning - 无法处理多类和连续的混合

标签 machine-learning scikit-learn classification

输出有四个类别:[0,1,2,3] 预测是[0,1]中的连续数(使用sigmoid函数后)

我在sklearn中尝试过混淆矩阵,f1_score,但是两种情况都出现错误:

ValueError: Can't handle mix of multiclass and continuous

如果我将其简化为二元分类器并使用AUC对其进行评估,则不会出现错误,这意味着AUC可以处理连续输入。

我的问题是在哪里可以找到 sklearn 中的评估,以便不仅可以处理多类,还可以处理连续输入。

最佳答案

在处理问题的细节之前,您需要确保您了解 AUC 指标以及如何正确使用它。

要了解 AUC 指标的含义,您可以开始 here .

本质上,您希望获得基于不同阈值的预测列表(即移动它们并每次都获得预测),计算每个阈值实例的误报率和漏报率,然后计算它们的 AUC。

计算和评估多类别 AUC 并不简单。您可以找到更多信息here ,但我在下面附上了一个很好的代码片段来帮助您入门。

# Compute macro-average ROC curve and ROC area

# First aggregate all false positive rates, 
# assuming fpr is a list of false positive values per class
all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)]))

# Then interpolate all ROC curves at this points
mean_tpr = np.zeros_like(all_fpr)
for i in range(n_classes):
    mean_tpr += interp(all_fpr, fpr[i], tpr[i])

# Finally average it and compute AUC
mean_tpr /= n_classes

fpr["macro"] = all_fpr
tpr["macro"] = mean_tpr
roc_auc["macro"] = auc(fpr["macro"], tpr["macro"])

# Plot all ROC curves
plt.figure()
plt.plot(fpr["micro"], tpr["micro"],
     label='micro-average ROC curve (area = {0:0.2f})'
           ''.format(roc_auc["micro"]),
     color='deeppink', linestyle=':', linewidth=4)

plt.plot(fpr["macro"], tpr["macro"],
     label='macro-average ROC curve (area = {0:0.2f})'
           ''.format(roc_auc["macro"]),
     color='navy', linestyle=':', linewidth=4)

colors = cycle(['aqua', 'darkorange', 'cornflowerblue'])
for i, color in zip(range(n_classes), colors):
    plt.plot(fpr[i], tpr[i], color=color, lw=lw,
         label='ROC curve of class {0} (area = {1:0.2f})'
         ''.format(i, roc_auc[i]))

plt.plot([0, 1], [0, 1], 'k--', lw=lw)
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Some extension of Receiver operating characteristic to multi-class')
plt.legend(loc="lower right")
plt.show()

关于machine-learning - 无法处理多类和连续的混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41784303/

相关文章:

python - 属性错误 : module 'statsmodels.formula.api' has no attribute 'OLS'

python - sklearn - 如何在单热编码时合并丢失的数据

python-3.x - 属性错误: _get_numeric_data ; Iris Dataset

python - 'ndarray' 类型的对象不是 JSON 可序列化的

machine-learning - 朴素贝叶斯分类器中的 RMSE

python - 添加优化会降低分类器算法的准确性、精确度和 f1

machine-learning - 完美的决策树分类

machine-learning - 如何在 Caffe 中检索图层

machine-learning - GoogLeNet 模型的微调

python - 使用pattern.en 格式化整个文本?