Scikit-Learn Decision Tree Probability of prediction being a or b?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
A scikit-learn decision tree can return both a predicted class and a probability estimate for each class. In a binary classification problem, that usually means “probability of A” and “probability of B.” The important detail is that these numbers come from the class distribution at the leaf node where the sample lands, so they are simple empirical proportions, not deeply calibrated probabilities.
How predict_proba Works
When a sample travels through a trained decision tree, it ends in one leaf. That leaf contains a set of training examples. Scikit-learn estimates the class probabilities by looking at the class frequencies in that leaf.
So if a leaf contains:
- 70 training rows of class
A - 30 training rows of class
B
then the predicted probabilities for any sample landing in that leaf are roughly:
- '
P(A) = 0.7' - '
P(B) = 0.3'
That is the basic interpretation of predict_proba for a decision tree.
A Concrete Example in scikit-learn
clf.classes_ tells you which column in predict_proba corresponds to which class label. In binary classification, the output usually has two numbers, one per class, and they sum to 1.0.
Probability of “A or B” Depends on Class Order
A common beginner mistake is assuming the first column is always class A and the second column is always class B. The correct mapping is given by clf.classes_.
If clf.classes_ is [0, 1], then the first probability belongs to class 0 and the second to class 1. If your labels are strings such as "A" and "B", the same rule applies: always check the class order instead of guessing.
Why the Probability Can Look Overconfident
Decision-tree probabilities are based on the training distribution inside a leaf. If a leaf has very few samples, the estimated probability can look more confident than it really should.
For example, if a leaf contains only two samples and both happen to be class A, the tree may output probability 1.0 for A. That does not mean the model has learned a perfect probability model. It only means that the leaf was pure on the training data reaching it.
This is why raw decision-tree probabilities are often less reliable than the label prediction itself, especially on small leaves.
Calibration Matters If You Need Good Probabilities
If the probabilities will drive thresholds, ranking, or business decisions, calibration may matter more than the tree itself. In scikit-learn, you can calibrate a classifier after fitting it.
Calibration does not change the fact that the tree classifies by leaves. It improves how the output probabilities align with observed frequencies on held-out data.
Common Pitfalls
- Forgetting to inspect
clf.classes_before interpreting the probability columns. - Treating decision-tree probabilities as perfectly calibrated probabilities.
- Ignoring the effect of tiny leaves on overconfident probability estimates.
- Assuming
predictandpredict_probaanswer different classes when they are based on the same leaf assignment. - Using raw tree probabilities for threshold-sensitive decisions without validation or calibration.
Summary
- '
predict_probain a decision tree is based on class frequencies in the final leaf.' - In binary classification, the two output probabilities correspond to the order in
clf.classes_. - The predicted class is usually the class with the highest leaf probability.
- Raw decision-tree probabilities can be overconfident when leaves are small.
- If you need stronger probability quality, check calibration rather than assuming the tree’s leaf frequencies are enough.
Related reading
- scikit-learn filling missing values by random sampling
- Scikit-learn, get accuracy scores for each class
- Scikit-learn GridSearch giving ValueError multiclass format is not supported error
- Scikit-learn How to obtain True Positive, True Negative, False Positive and False Negative
- Scikit learn - fit_transform on the test set
- scipy kdtree with meta data
- Scikit-learn Ridge classifier extracting class probabilities
- search for interval overlap in list of intervals?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.