sklearn 绘制roc曲线_sklearn的roc曲线[python]

在Python中,通过sklearn库绘制ROC曲线时,需要理解`y_true`和`y_score`的含义。`y_true`是实际的二进制标签,而`y_score`是预测的概率分数。从包含TP、FP、FN、TN的数据文件中,分别提取这些值,然后调用`roc_curve`计算FPR和TPR,并用`auc`计算AUC。最后,可以绘制ROC曲线以评估检测器的性能。
摘要由CSDN通过智能技术生成

I have an understanding problem by using the roc libraries.

I am writing a program which evalutes detectors (haarcascade, neuronal networks) and want to evaluate them.

So I already have the data saved in a file in the following format:

0.5 TP

0.43 FP

0.72 FN

0.82 TN

...

whereas TP means True Positive, FP - False Positivve, FN - False Negative, TN - True Negative

I parse it and fill 4 arrays with this data set.

Then I want to put this in

fpr, tpr = sklearn.metrics.roc_curve(y_true, y_score, average='macro', sample_weight=None)

but how to do this? What is y_true in my case and y_score?

afterwards, I put it fpr, tpr in

auc = sklearn.metric.auc(fpr, tpr)

解决方案

Quotting Wikipedia:

The ROC is created by plotting the FPR (false positive rate) vs the TPR (true positive rate) at various thresholds settings.

In order to compute FPR and TPR, you must provide the true binary value and the target scores to the function sklearn.metrics.roc_curve.

So in your case, I would do something like this :

from sklearn.metrics import roc_curve

from sklearn.metrics import auc

# Compute fpr, tpr, thresholds and roc auc

fpr, tpr, thresholds = roc_curve(y_true, y_score)

roc_auc = auc(y_true, y_score)

# Plot ROC curve

plt.plot(fpr, tpr, label='ROC curve (area = %0.3f)' % roc_auc)

plt.plot([0, 1], [0, 1], 'k--') # random predictions curve

plt.xlim([0.0, 1.0])

plt.ylim([0.0, 1.0])

plt.xlabel('False Positive Rate or (1 - Specifity)')

plt.ylabel('True Positive Rate or (Sensitivity)')

plt.title('Receiver Operating Characteristic')

plt.legend(loc="lower right")

If you want to have a deeper understanding of how the False positive rate and the True positive rate are computed for all the possible thresholds values, I suggest you to read this article

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值