I am trying to use Caret for building random forest model for binary classification. I have used randomForest source package to do this in past and it worked fine but using Caret my output is binary rather then probability. With type='prob', it gives error
Error in [.data.frame
(out, , obsLevels, drop = FALSE) : undefined columns selected
I am using the same syntax (I hope) for both. This is what I used to get with source randomForest package.
>fit = randomForest(x = a[,-1], y = as.factor(a[,1]),ntree=120)
>head(predict(fit, newdata = test_data[,-c(1:2)], type = "prob")[,2])
1 2 3 4 5 6
0.04166667 0.03333333 0.55833333 0.80000000 0.87500000 0.04166667
Now, using Caret I am trying to do the same but its not accepting " type='prob' " in predict function, giving me the error
>rf_model<-train(x = a[,-1], y = as.factor(a[,1]),method="rf",ntree=120)
>head(predict(rf_model, test_data[,-c(1:2)], type="prob"))
Error in `[.data.frame`(out, , obsLevels, drop = FALSE) :
undefined columns selected
Rather when I take out the "type", it gives me
>head(predict(rf_model, test_data[,-c(1:2)]))
[1] 0 0 1 1 1 0
Levels: 0 1
How do I get output in probabilities?
I need to create multiple algorithms after this and I think Caret would be more homogeneous to do that. I am sure I am missing something here but being new to Caret I don't know what.