R编程-如何将模型输出转换为数据帧

时间:2019-01-29 09:18:52

标签: r r-caret

以下是我使用交叉验证方法运行KNN模型的脚本。

## cross validation

library(caret)
cvroc <- trainControl(method = "repeatedcv",
                   number = 10, # number of iteration 
                   repeats = 3,
                   classProbs = TRUE,
                   summaryFunction = twoClassSummary)

#KNN Model
set.seed(222)
fit_roc <- train(admit ~. , 
             data = training,
             method = 'knn',
             tuneLength = 20,
             trControl = cvroc, .
             preProc = c("center","scale"), 
             metric = "ROC",
             tuneGrid =expand.grid(k=1:60))
fit_roc

KNN model output

问题: 我的问题是,如何将模型的输出转换为data.frame? 我用下面的命令给出了错误。

aa <- data.frame(fit_roc) 

谢谢!

1 个答案:

答案 0 :(得分:0)

根据所需的输出部分,可以执行以下操作:指向fit_roc$whatever you want to extract

fit_roc$results