python - 错误:不支持多类格式,AUROC
问题描述
我想计算 ROC 分数,但错误被标记为“不支持多类格式”我不太确定为什么会出现错误,因为我已经将 y 更改为二进制。
y = dat['category'].map( {'sport': 0, 'business': 1, 'politics': 2, 'tech': 3, 'entertainment': 4} ).astype(int)
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=2)
我已经建立了分类器并计算了概率
from sklearn.metrics import roc_curve, roc_auc_score
r_auc = roc_auc_score(y_test, r_probs)
lr_auc = roc_auc_score(y_test, lr_probs)
rf_auc = roc_auc_score(y_test, rf_probs)
gb_probs = roc_auc_score(y_test, gb_probs)
print("Random Prediction: AUROC = %.3f" %(r_auc))
print("Logistic Regression: AUROC = %.3f" %(lr_auc))
print("Random Forest: AUROC = %.3f" %(rf_auc))
print("Gradient Boosting: AUROC = %.3f" %(gb_probs))
错误:
ValueError Traceback (most recent call last)
<ipython-input-230-4ba9c6da7108> in <module>
2 from sklearn.metrics import roc_curve, roc_auc_score
3
----> 4 r_auc = roc_auc_score(y_test, r_probs)
5 lr_auc = roc_auc_score(y_test, lr_probs)
6 rf_auc = roc_auc_score(y_test, rf_probs)
~\Anaconda3\lib\site-packages\sklearn\metrics\ranking.py in roc_auc_score(y_true, y_score, average, sample_weight, max_fpr)
353 return _average_binary_score(
354 _binary_roc_auc_score, y_true, y_score, average,
--> 355 sample_weight=sample_weight)
356
357
~\Anaconda3\lib\site-packages\sklearn\metrics\base.py in _average_binary_score(binary_metric, y_true, y_score, average, sample_weight)
71 y_type = type_of_target(y_true)
72 if y_type not in ("binary", "multilabel-indicator"):
---> 73 raise ValueError("{0} format is not supported".format(y_type))
74
75 if y_type == "binary":
ValueError: multiclass format is not supported
有人可以帮忙吗:(
解决方案
推荐阅读
- php - Laravel 更新带有 foreach 循环的单行
- import - Jest 编译代码的方式与 ts-node 不同
- flutter - 在 Flutter 中加载图像并处理加载异常的正确方法是什么
- webpack - 为什么 Webpack 5 会返回一个非零错误代码作为性能提示?
- clojurescript - ClojureScript:TypeError:$jscomp.inherits 不是函数
- mpi - MPI - 单方面的沟通
- vue.js - 从父组件中的发出事件中检索 $event 对象
- go - 我需要释放指针吗
- asp.net-core - 代码覆盖率选项卡未在 Azure DevOps 中显示报告
- php - PHP如何更新数据库表中不同列中上传的多个文件