r - How to use trained caret object to predict on new data (not used while training)? -
i using caret package train random forest model on training dataset. have used 10-fold cross validation object randomforestfit. use object predict on new data set test_data. want respective class probabilities. how that?
i have been using extractprob function follows :
extractprob(randomforestfit, textx = test_data_predictors, testy = test_data_labels) but it's giving me unexpected results.
from extractprob page example, need wrap model in list:
knnfit <- train(species ~ ., data = iris, method = "knn", trcontrol = traincontrol(method = "cv")) rdafit <- train(species ~ ., data = iris, method = "rda", trcontrol = traincontrol(method = "cv")) predict(knnfit) predict(knnfit, type = "prob") bothmodels <- list(knn = knnfit, tree = rdafit) predict(bothmodels) extractprediction(bothmodels, testx = iris[1:10, -5]) extractprob(bothmodels, testx = iris[1:10, -5]) so following should work:
extractprob(list(randomforestfit), textx = test_data_predictors, testy = test_data_labels) edit:
and yes, preprocessing used. documentation:
these processing steps applied during predictions generated using predict.train, extractprediction or extractprobs (see details later in document). pre-processing not applied predictions directly use object$finalmodel object.
Comments
Post a Comment