使用scikit-learn绘制接收者操作特征曲线时遇到问题?

我想绘制接收者操作特征曲线,因此我做了以下操作:

from sklearn.metrics import roc_curve, aucpredictions = auto_wclf.predict_proba(X_test)false_positive_rate, recall, thresholds = roc_curve(y_test, predictions[:, 1])roc_auc = auc(false_positive_rate, recall)plt.title('Receiver Operating Characteristic')plt.plot(false_positive_rate, recall, 'b', label='AUC = %0.2f' % roc_auc)plt.legend(loc='lower right')plt.plot([0, 1], [0, 1], 'r--')plt.xlim([0.0, 1.0])plt.ylim([0.0, 1.0])plt.ylabel('Recall')plt.xlabel('Fall-out')plt.show()

但我得到了以下异常:

Traceback (most recent call last):  File "plot.py", line 172, in <module>    false_positive_rate, recall, thresholds = roc_curve(y_test, predictions[:, 1])  File "plot.py", line 890, in roc_curve    y_true, y_score, pos_label=pos_label, sample_weight=sample_weight)  File "/usr/local/lib/python2.7/site-packages/sklearn/metrics/metrics.py", line 710, in _binary_clf_curve    raise ValueError("Data is not binary and pos_label is not specified")ValueError: Data is not binary and pos_label is not specified

我有一个多标签分类问题(5个类别)。你们有任何关于如何绘制这个图的想法吗?提前感谢大家。


回答:

是的,ROC曲线“是一个图形绘图,展示了二元分类系统在其判别阈值变化时的性能”(维基百科)。

此外,“对于超过两个类别的分类问题,ROC曲线的扩展一直是繁琐的,因为自由度随类别数量的增加而呈二次增加,ROC空间具有c(c-1)个维度,其中c是类别数量。”(同一维基页面)。由于你有5个类别甚至是多标签,ROC曲线并不适合你。

请使用像汉明损失F1分数准确率精确度召回率这样的指标——选择最适合你任务的一个。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注