首页 > 解决方案 > 如何在 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()

标签: pythonmatplotlibroc

解决方案


错误指向CountVectorizer不是 ROC 曲线。这可能会有所帮助CountVectorizer:未安装词汇表


推荐阅读