RandomForest package with R mse calculation

I feel like I am missing something very basic here.

I ran a random forest regression:

INTERP.rf<-randomForest(y~.,data=df,importance=T,mtry=3,ntree=300)

      

and then extracted the predictions for the training set:

rf.predict<-predict(INTERP.rf,df,type="response")

      

% var from rf.predict looked too low, so I checked it:

MSE.rf<-sum((rf.predict-y)^2)/length(y)

      

... and got a completely different answer than inspecting the rf.predict object.

Please can anyone highlight my error?

+3


source to share


1 answer


The correct way to do it is to use:

rf.predict<-predict(INTERP.rf)

      



I didn't know what I needed to use predict.randomforest(model)

, not predict.randomForest(model,trainingData)

to get OOB predictions.

Thanks @joran and @Vlo for helpful comments

+1


source







All Articles