python - 如何在 python 中用文本数据绘制 ROC 曲线?
问题描述
我想绘制 ROC 曲线,以便使用幼稚模型作为分类来显示 TPR 与 FPR。
我已经对我的数据进行了矢量化处理。
当我运行代码时,它显示以下错误:
raise NotFittedError(msg % {'name': type(estimator).__name__}) sklearn.exceptions.NotFittedError: CountVectorizer - Vocabulary wasn't fitted
代码:
#Create ROC curve
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
pred_probas = pipeline.predict_proba(X_test)[:,1]
fpr,tpr,_ = roc_curve(y_test, pred_probas)
roc_auc = auc(fpr,tpr)
plt.plot(fpr,tpr,label='area = %.2f' %roc_auc)
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.legend(loc='lower right')
plt.show()
解决方案
错误指向CountVectorizer
不是 ROC 曲线。这可能会有所帮助CountVectorizer:未安装词汇表
推荐阅读
- sql - 选择 sql 查询的联合部分
- java - 按数字顺序对数字的 ArrayList 进行排序
- spring - 如何在 Spring JSON 查询中不发送 @IdClass 对象
- react-native - eslint prettier 需要文件重排
- reactjs - 用本地存储反应路由器私有路由?
- node.js - 异步不回拨?
- php - 如何在仅将该商品添加到购物车的每一行末尾编写“添加到购物车”?
- python - 在 Windows 上使用 pyinstaller 从 .py 构建 .dmg 文件?
- regex - 未找到 Mod 重写页面
- python - 如何检测模糊的斑点?