混淆矩阵值
截止/ TP / FP / TN / FN
0.1 100 50 500 450
0.2 150 100 450 400
0.3 250 150400300
0.4 300 200 350 250
0.5 350 250300200
0.6 350300250200
0.7 400 350 200 150
0.8 400 400 150 150
0.9450450100100
1.0 500 500 50 50
您可以使用以下代码:
## 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
产生以下情节: