#logistic- caret::train
#划分数据集
set.seed(123)
folds <- createFolds(y=data$Groups,k=10)文章来源地址https://www.toymoban.com/news/detail-604414.html
# 建一个放auc值的空向量
auc<-as.numeric()
Errorrate<-as.numeric()
accuracy<-as.numeric()
sensitivity<-as.numeric()
specificity<-as.numeric()
roc <- vector("list", 10)
#设置交叉验证参数
set.seed(123) #使结果具有可重复性
trainControl<- trainControl(method = "cv", number = 10)
for(i in 1:10){
test <- data[folds[[i]],]
train <- data[-folds[[i]],]
logit<- caret::train(Groups ~ ., data = train,
family = binomial(link = "logit"),
trainControl= trainControl
#linout = FALSE,
#trace = FALSE
)
#预测
pred <- predict(logit, newdata = test, probability = TRUE)
prob <- predict(logit, newdata = test, type = "prob")[,2]
#混淆矩阵
table<-table(Predicted=pre
文章来源:https://www.toymoban.com/news/detail-604414.html
到了这里,关于R语言-logistic回归的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!