【问题标题】:How to plot ROC curve in python with text data?如何在 python 中用文本数据绘制 ROC 曲线?
【发布时间】:2020-11-06 00:33:25
【问题描述】:

我想绘制 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()

【问题讨论】:

    标签: python matplotlib roc


    【解决方案1】:

    错误指向CountVectorizer而不是ROC曲线。这可能会有所帮助CountVectorizer: Vocabulary wasn't fitted

    【讨论】:

      猜你喜欢
      • 2014-09-20
      • 2017-09-11
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      • 2012-01-01
      • 2019-04-11
      • 2019-06-01
      • 2017-10-14
      相关资源
      最近更新 更多