如何根据给定值在rStudio中绘制ROC曲线?

问题描述 投票:0回答:1

混淆矩阵值

  1. 截止/ TP / FP / TN / FN

  2. 0.1 100 50 500 450

  3. 0.2 150 100 450 400

  4. 0.3 250 150400300

  5. 0.4 300 200 350 250

  6. 0.5 350 250300200

  7. 0.6 350300250200

  8. 0.7 400 350 200 150

  9. 0.8 400 400 150 150

  10. 0.9450450100100

  11. 1.0 500 500 50 50

r roc
1个回答
0
投票

您可以使用以下代码:

## your data
df <- read.table(header = TRUE, text = "
Cut_off TP FP TN FN
0.1 100 50 500 450
0.2 150 100 450 400
0.3 250 150 400 300
0.4 300 200 350 250
0.5 350 250 300 200
0.6 350 300 250 200
0.7 400 350 200 150
0.8 400 400 150 150
0.9 450 450 100 100
1.0 500 500 50 50")

## calculate False Positive ratio
df$FPR <- df$FP/(df$FP + df$TN)
## calculte True Positive Ratio
df$TPR <- df$TP/(df$TP + df$FN)

## plot the ROC with base plot
plot(df$FPR, df$TPR, type = "b", 
     xlim = c(0,1), ylim = c(0,1), 
     main = 'ROC Curve',
     xlab = "False Positive Rate (Specificity)",
     ylab = "True Positive Rate (Sensitivity)",
     col = "blue")
abline(a = 0, b = 1, lty=2, col = "grey") ### pure chance line

产生以下情节:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.