How to show predictions for models fitted using caret in R

r
caret

#1

Hello,

I am using caret for modeling so that I can use cross validation.Below is my code for rpart:

Control <- trainControl(method='cv', number=5,repeats = 10,returnResamp='none')
rpartModel <- train(Loan_Status~.,data = training, 
                  method='rpart', 
                  trControl=Control,  
                  metric = "Accuracy")

However I am not getting the predicted values:

> rpartModel$pred
NULL

How do I get the predictions??r


#2

Hi @pagal_guy

are you sure $pred is part of the return values it is documented no where?. If so I think it will be on the final mode Usually you do a predict on the training set.

firstprediction <-predict(rpartModel, training)

then on the test if call testdata

testprediction <-predict(raprtModel, newdata=testdata)


#3

Hi pagal,

Where did you get the instructions to setup the Control parameters?
In your Control, what is the reason for setting returnResamp='none' ?

You might want to remove this parameter and try to create the model again.


#4

Hi @r_achar

I did not know this parameter, thanks to notice it.
For other people the definition of returnResamp

returnResamp: a character string containing one of the following values: “all”, “final” or “none”. This specifies how much of the resampled performance measures to save

Alain


#5

Pagal,

Good to know that. Thank you.

Did you create the model after changing/removing the parameter? If yes, did you get what you were looking for?


#6

Hello Everyone,

Many Thanks for all your inputs.
There is a option savePred =T which has to be passed onto control to get the predictions.


#7

Hi @pagal_guy

good to mention this parameter, what do you want to do with this? Do you want to calculated the variance of the cross validations ? and the differences between the 5 folds and repeats?

Alain