TL;DR :
Is there something I can flag in the original randomForest
call to avoid having to re-run the predict
function to get predicted categorical probabilities, instead of just the likely category?
Details:
I am using the randomForest package.
I have a model something like:
model <- randomForest(x=out.data[train.rows, feature.cols],
y=out.data[train.rows, response.col],
xtest=out.data[test.rows, feature.cols],
ytest=out.data[test.rows, response.col],
importance= TRUE)
where out.data
is a data frame, with feature.cols
a mixture of numeric and categorical features, while response.col
is a TRUE
/ FALSE
binary variable, that I forced into factor
so that randomForest
model will properly treat it as categorical.
All runs well, and the variable model
is returned to me properly. However, I cannot seem to find a flag or parameter to pass to the randomForest
function so that model
is returned to me with the probabilities of TRUE
or FALSE
. Instead, I get simply predicted values. That is, if I look at model$predicted
, I'll see something like:
FALSE
FALSE
TRUE
TRUE
FALSE
.
.
.
Instead, I want to see something like:
FALSE TRUE
1 0.84 0.16
2 0.66 0.34
3 0.11 0.89
4 0.17 0.83
5 0.92 0.08
. . .
. . .
. . .
I can get the above, but in order to do so, I need to do something like:
tmp <- predict(model, out.data[test.rows, feature.cols], "prob")
[test.rows
captures the row numbers for those that were used during the model testing. The details are not shown here, but are simple since the test row IDs are output into model
.]
Then everything works fine. The problem is that the model is big and takes a very long time to run, and even the prediction itself takes a while. Since the prediction should be entirely unnecessary (I am simply looking to calculate the ROC curve on the test data set, the data set that should have already been calculated), I was hoping to skip this step. Is there something I can flag in the original randomForest
call to avoid having to re-run the predict
function?