In regression problems random forests yield a prediction for each case by averaging the results of each single tree in the forest. I would like to draw a 95% prediction interval around each prediction. There is a nice option interval="prediction"
for the prediction method of linear models, but there's no such thing for random forests (at least in the R package randomForest). Can I presume that the casewise predictions of the single trees are normally distributed and apply the formula http://mathurl.com/bbvuvx9 or should I determine it by bootstrapping? If so, how can this be done?
2 Answers
I'm assuming you're talking about the continuous response case. If so, I'd recommend the quantregForest
package that layers on top of the basic randomForest
package and gives conditional quantile predictions. The documentation is quite good. Instead of assuming a gaussian distribution, it build an empirical density function from the terminal nodes.
-
2$\begingroup$ stats.ox.ac.uk/~meinshau/quantregforests.pdf describes the technique. $\endgroup$– B_MinerCommented Feb 11, 2013 at 17:30
-
1$\begingroup$ @Shea Parkes: I did not know this package, thanks for the hint. $\endgroup$– user7417Commented Feb 12, 2013 at 10:00
-
$\begingroup$ @B_Miner: I already downloaded the pdf and shall dig into it... Certainly I'll come back with more questions ;-) $\endgroup$– user7417Commented Feb 12, 2013 at 10:00
The ranger
package supports quantile predictions and hence prediction intervals: predict(ranger_fit, type = "quantile", quantiles = c(0.025, 0.975))
.