Ntlk &Python,绘制ROC曲线 [英] Ntlk & Python, plotting ROC curve

查看:68
本文介绍了Ntlk &Python,绘制ROC曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Python 中使用 nltk,我想绘制我的分类器(朴素贝叶斯)的 ROC 曲线.是否有任何绘制它的功能,或者我必须跟踪真阳性率和假阳性率?

I am using nltk with Python and I would like to plot the ROC curve of my classifier (Naive Bayes). Is there any function for plotting it or should I have to track the True Positive rate and False Positive rate ?

如果有人能指点我一些已经在做的代码就好了...

It would be great if someone would point me to some code already doing it...

谢谢.

推荐答案

PyROC 看起来很简单:教程源代码

PyROC looks simple enough: tutorial, source code

这就是它与 NLTK 朴素贝叶斯分类器的工作方式:

This is how it would work with the NLTK naive bayes classifier:

# class labels are 0 and 1
labeled_data = [
    (1, featureset_1),
    (0, featureset_2),
    (1, featureset_3),
    # ...
]

# naive_bayes is your already trained classifier,
# preferrably not on the data you're testing on :)

from pyroc import ROCData

roc_data = ROCData(
    (label, naive_bayes.prob_classify(featureset).prob(1))
    for label, featureset
    in labeled_data
)
roc_data.plot()

  • ROC 仅适用于二元分类器.如果您有三个类,则可以分别衡量正类和负类的表现(通过将其他两个类计为 0,就像您建议的那样).
  • 库期望决策函数的输出作为每个元组的第二个值.然后它尝试所有可能的阈值,例如f(x) >= 0.8 => 分类为 1,并为每个阈值绘制一个点(这就是最终得到曲线的原因).因此,如果您的分类器猜测类别 0,您实际上想要一个接近于零的值.这就是为什么我提出 .prob(1)

这篇关于Ntlk &Python,绘制ROC曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆