在scikit中绘制ROC曲线仅产生3个点 [英] Plotting a ROC curve in scikit yields only 3 points

查看:262
本文介绍了在scikit中绘制ROC曲线仅产生3个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:scikit的roc_curve函数对于特定数据集仅返回3点. 为什么会这样,以及我们如何控制要获得多少积分呢?

TLDR: scikit's roc_curve function is only returning 3 points for a certain dataset. Why could this be, and how do we control how many points to get back?

我正在尝试绘制ROC曲线,但始终得到一个"ROC三角形".

I'm trying to draw a ROC curve, but consistently get a "ROC triangle".

lr = LogisticRegression(multi_class = 'multinomial', solver = 'newton-cg')
y = data['target'].values
X = data[['feature']].values

model = lr.fit(X,y)

# get probabilities for clf
probas_ = model.predict_log_proba(X)

只需确保长度正确即可:

Just to make sure the lengths are ok:

print len(y)
print len(probas_[:, 1])

两者都返回13759.

Returns 13759 on both.

然后运行:

false_pos_rate, true_pos_rate, thresholds = roc_curve(y, probas_[:, 1])
print false_pos_rate

返回[0. 0.28240129 1.]

returns [ 0. 0.28240129 1. ]

如果我叫阈值,则会得到array([0.4822225,-0.5177775,-0.84595197])(总是只有3分).

If I call threasholds, I get array([ 0.4822225 , -0.5177775 , -0.84595197]) (always only 3 points).

因此,我的ROC曲线看起来像三角形也就不足为奇了.

It is therefore no surprise that my ROC curve looks like a triangle.

我不明白的是为什么scikit的roc_curve只返回3分.帮助非常感谢.

What I cannot understand is why scikit's roc_curve is only returning 3 points. Help hugely appreciated.

推荐答案

点的数量取决于输入中唯一值的数量.由于输入向量只有2个唯一值,因此该函数可提供正确的输出.

The number of points depend on the number of unique values in the input. Since the input vector has only 2 unique values, the function gives correct output.

这篇关于在scikit中绘制ROC曲线仅产生3个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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