使用pROC包绘制ROC曲线
#####***绘制ROC曲线***#####
library("pROC")
N <- dim(data2)[1] #数据长度
set.seed(1234) #设置随机种子
ind <- sample(2, N, replace=TRUE, prob = c(0.8,0.2))
data_train <- data2[ind == 1,] #生成训练集
data_test <- data2[ind == 2,] #生成测试集
real <- data_test$决定 #提取真值
dating <- glm(formula = 决定 ~ ., family = binomial(link = "logit"), data = data_train) #测试数据
pre <- predict.glm(dating, type = 'response', newdata = data_test) #预测数据
date_roc <- roc(real, pre) #计算ROC
plot(date_roc, print.auc = TRUE, auc.polygon = TRUE, legacy.axes = TRUE,
grid = c(0.1, 0.2), grid.col = c("green", "red"), max.auc.polygon = TRUE,
auc.polygon.col = "skyblue", print.thres = TRUE, xlab = "特异度", ylab = "灵敏度",
main = "逻辑回归结果") #绘制ROC曲线