My main concern is that i need to understand that how does the random forest do majority voting in scikit learn source code. I did not find that specific code in source code of RandomForest. if anybody knows, then kindly explain that. Thanks
To quote from the documentation:
The predicted class probabilities of an input sample are computed as the mean predicted class probabilities of the trees in the forest. The class probability of a single tree is the fraction of samples of the same class in a leaf.
The predictions are then simply the class with the highest average class probability.
You can find the source code here.
Note that this is different from classical majority voting which is usually understood to be the most common class prediction among trees whereas here the voting happens on the class probability level.
The source code for regression is here:
The predicted regression target of an input sample is computed as the mean predicted regression targets of the trees in the forest.
A Random Forest is an ensemble of decision trees. Each decision tree will reach a "conclusion" (i.e., a prediction) about each observation. All trees are then combined together.
What does it mean?
- if you are training a Random Forest regressor, this combination is an average of each tree's prediction.
- if you are training a Random Forest classifier, each tree's classification is combined into a final classification through a "majority vote" mechanism.