0

below are my scripts in running KNN model using cross validate method.

## 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

Question: My question will be, how can i convert the output from the model into a data.frame? i used the command below it gives error.

aa <- data.frame(fit_roc) 

Thanks!

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Jimmy Wong
  • 17
  • 1
  • 3
  • 3
    Welcome to SO! Take a look at `str(fit_roc)`. You'll somewhere find the dataframe. If not, condider to share a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – markus Jan 29 '19 at 09:23
  • Check out `broom` package which is made exactly for this purpose – Sergey Bushmanov Jan 29 '19 at 09:34
  • Thanks Sergey, will look up broom package.! – Jimmy Wong Jan 30 '19 at 05:36

1 Answers1

1

Depending on which part of the output you want, you can do the following: The point is fit_roc$whatever you want to extract

fit_roc$results
NelsonGon
  • 13,015
  • 7
  • 27
  • 57