Recursive partitioning
Quick answer
A decision tree predicts by following a sequence of feature tests from a root node to a leaf. Training chooses tests that make the resulting groups more useful for prediction; inference only follows the learned tests. Examples run locally with Python 3.13.5, scikit-learn 1.8.0, NumPy 2.3.5 and SciPy 1.17.0 when imported. ByteMind library execution is unverified.
Partition four parcels
x=[1,2,5,6]print([[v for v in x if v<=3.5],[v for v in x if v>3.5]])Expected output:
[[1, 2], [5, 6]]The left child includes the threshold itself. Neither child duplicates a sample.
How it works
Consider a parcel sorting model with weight as its only feature. A node containing weights 1, 2, 5 and 6 can split at 3.5: the left child receives weights at most 3.5 and the right child receives the rest. Each child can repeat the process using the same or another feature. The root contains all training rows; an internal node has children; a leaf stores a prediction. A classification leaf predicts a class using its class frequencies (weighted frequencies when weights are used). In CART, candidate splits are binary and a greedy search selects a locally useful split, not a globally optimal tree. Axis-aligned tests create rectangular regions in feature space; a diagonal boundary may require many splits. Prediction cost depends on the path depth; it is not necessarily logarithmic for an unbalanced tree. In scikit-learn 1.8, DecisionTreeClassifier takes numerical features; encode nominal categories deliberately instead of assigning arbitrary ordinal meanings. Use only finite numeric data in these examples. Missing-value support is criterion and configuration dependent; verify before using it. Scaling usually is not needed for an ordinary threshold tree, but numerical precision and ties can affect the fitted structure.
Inspect a fitted stump
from sklearn.tree import DecisionTreeClassifierm=DecisionTreeClassifier(max_depth=1,random_state=7).fit([[1],[2],[5],[6]],[0,0,1,1])print(float(m.tree_.threshold[0]),m.predict([[3.5],[4]]).tolist())Expected output:
3.5 [0, 1]The model chooses the midpoint between 2 and 5. Inspect an individual prediction path rather than guessing from a feature name.
Common mistakes
Do not equate the root feature with a causal variable. A tree can learn accidental associations. A threshold belongs to the left child when the test is <=; reversing that boundary changes a prediction.
Practice and next steps
Trace weights 2, 3.5 and 7 through the fitted stump, then explain why a new split below the root may improve a mixed leaf. Complete the knowledge check and coding exercise. Next: Gini and entropy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Recursive partitioning — knowledge check
Apply recursive partitioning to new examples.
Which node stores the final prediction?
A test is weight <= 5. Where does weight 5 go?
What is greedy split search?
What determines the number of tests at inference?
Why avoid arbitrary integer codes for nominal features?