Extract from sklearn documentation of randomForestClassifier

Attached is an extract from the RandomForestClassifier documentation of sklearn. The last line,"The class probabilities of a single tree is the fraction of samples of the same class in a leaf." is something I am not able to grasp, Could someone please help me understand this.!!!!


1 Answer 1


It's explaining how the predict_proba works. If at the lowest level of the tree, you have 80 samples of class 1 and 20 samples of class 0 in a leaf. then the class probability of 1 is 80 / ( total number of class1 samples in the whole population ), and the mean of those class probabilities across all trees is computed. And that's how you get the results from the predict_proba method.

  • $\begingroup$ When we run predict_proba the function doesn’t know the actual classes .. how can there be a (single)leaf that can differentiate between classes in it. $\endgroup$ Dec 16, 2019 at 16:07
  • $\begingroup$ It does know the classes, when you use predict_proba, the tree has already fit the data, your data points ( to be predicted ) just follow the "path" that the tree drew out of your training data. If your point lands in a leaf where the probability is 0.8, a 0.8 probability will be assigned to it. $\endgroup$
    – Blenz
    Dec 16, 2019 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.