I want to get classification probabilities of each class by each tree in the randomForest.
(1) This outputs individual outputs but its type is response, not probabilities:
predict(rf_cl, newdata, predict.all=TRUE)$individual
(2) This outputs probabilities but it belongs to the forest not all trees:
predict(rf_cl, newdata, type="prob")
(3) When I tried this, I got the same output as the first one.
predict(rf_cl, newdata, predict.all=TRUE, type="prob")$individual
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this. Thanks in advance.
The member decision trees of a
randomForestdecision tree ensemble make "pure" predictions. That is, the probability of the winning category is1.0, and the probabilities of all other categories are0.0.The random forest computes the aggregate probability using the voting mechanism - the number of "pure" predictions (aka votes) for each class, divided by the total number of member decision trees. Knowing this will help you choose the number of decision trees in order to achieve the desired "precision" of aggregate probabilities, and avoid any ties. For example, when modeling a binary target, then you should choose an odd number of member decision trees to avoid a
0.5vs.0.5tie.