当前位置:   article > 正文

R语言-logistic回归_logistic回归分析r语言代码

logistic回归分析r语言代码

#logistic- caret::train
#划分数据集
set.seed(123)
folds <- createFolds(y=data$Groups,k=10)

# 建一个放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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/629953
推荐阅读
相关标签
  

闽ICP备14008679号