Threshold Splits
See how feature thresholds divide data into left and right groups.
Big Idea
Before a decision tree can decide which split is best, it first needs to decide where it is allowed to split.
For numeric features, a decision tree does not test every possible number. Instead, it creates a small set of candidate thresholds from the data itself.
These candidate thresholds become the only locations where the tree will consider making a split.
Real World Example
A hospital wants to build a machine learning model that predicts whether a patient has heart disease. Each row represents one patient. The features are Age and Resting Blood Pressure, while the target indicates whether heart disease was diagnosed.
Before we look at the numbers, here is the vocabulary we will use throughout this lesson:
- Sample — one row in the dataset (one patient)
- Feature — an input column the model uses to make a prediction (Age or Resting BP)
- Target — the output label we want to predict (Heart Disease: 0 = no, 1 = yes)
We have collected the following data for twelve patients.
| Patient | Age | Resting BP | Heart Disease |
|---|---|---|---|
| P1 | 42 | 118 | 0 |
| P2 | 45 | 122 | 0 |
| P3 | 45 | 128 | 0 |
| P4 | 48 | 130 | 0 |
| P5 | 50 | 135 | 0 |
| P6 | 53 | 138 | 1 |
| P7 | 55 | 142 | 1 |
| P8 | 55 | 145 | 1 |
| P9 | 58 | 148 | 1 |
| P10 | 60 | 150 | 1 |
| P11 | 63 | 155 | 1 |
| P12 | 67 | 160 | 1 |
The interactive visualization on the right plots these patients.
- Blue = No Heart Disease
- Red = Heart Disease
Notice that older patients tend to appear in the upper-right portion of the graph.
Computing Candidate Thresholds
Suppose the decision tree wants to split on Age. It begins with every Age value in the dataset, sorted from smallest to largest.
Original Age values
42, 45, 45, 48, 50, 53, 55, 55, 58, 60, 63, 67
↓
Remove duplicate values
42, 45, 48, 50, 53, 55, 58, 60, 63, 67
Why remove duplicates? A threshold is meant to separate one group of patients from another. If two patients share the same Age, no cut point between identical values can move one patient to the left and the other to the right. Duplicates are collapsed so the tree only considers boundaries where a split could actually change the grouping.
Next, a candidate threshold is placed halfway between each pair of consecutive unique values.
The midpoint formula is
ti=2vi+vi+1where
- vi is one sorted unique value
- vi+1 is the next unique value
Applying this formula to our sorted unique ages gives nine candidate thresholds:
t1t2t3t4t5t6t7t8t9=242+45=43.5=245+48=46.5=248+50=49=250+53=51.5=253+55=54=255+58=56.5=258+60=59=260+63=61.5=263+67=65These are the only candidate thresholds that the decision tree will evaluate.
▸Why Midpoints?
You might wonder:
Why not split at Age = 45?
The issue is not the number 45 itself — it is that any threshold strictly between 45 and 48 divides the patients in exactly the same way. Consider these four possibilities:
- 45.2
- 46
- 46.5
- 47.9
For each one, every patient with Age ≤ threshold lands in the left group, and every patient with Age > threshold lands in the right group. The partition is identical.
Testing infinitely many values between 45 and 48 would be wasteful. The decision tree therefore picks a single representative: the midpoint. This keeps the search small while preserving every distinct way the data can be divided.
▸Threshold Visualization
Use the interactive visualization to see how a threshold partitions the dataset. Select different candidate values and observe the following:
- Blue points — patients with no heart disease
- Red points — patients with heart disease
- Dashed vertical line — the active Age threshold
- Left child — all patients with Age ≤ threshold (left of the line)
- Right child — all patients with Age > threshold (right of the line)
As you move the threshold, watch how patients slide between the left and right groups. Older patients with higher resting blood pressure tend to cluster on the right side of the plot — but at this stage we are only learning how the data is divided. We are not yet judging whether a split is good or bad.
▸Common Mistake
A common misconception is that the threshold must equal one of the feature values.
This is not true.
Thresholds are usually between two observed values, not directly on top of one.
▸Key Takeaway
Threshold splits answer one question:
Where can a decision tree split?
They do not tell us which threshold is best.
Now that we know every location where a decision tree is allowed to split the data, the next question is: Which threshold is the best one? In the next lesson, we'll use Gini Impurity to score every candidate threshold and choose the best split.
Interactive
Threshold Split Demo
Change the feature and threshold to see how the dataset splits and how weighted Gini updates.
Split rule (Age only)
Age ≤ 51.5
Midpoints between consecutive unique Age values
Left region
Age ≤ 51.5
5
patients
P1, P2, P3, P4, P5
Right region
Age > 51.5
7
patients
P6, P7, P8, P9, P10, P11, P12
How patients are divided
| Patient | Age | Region |
|---|---|---|
| P1 | 42 | Left |
| P2 | 45 | Left |
| P3 | 45 | Left |
| P4 | 48 | Left |
| P5 | 50 | Left |
| P6 | 53 | Right |
| P7 | 55 | Right |
| P8 | 55 | Right |
| P9 | 58 | Right |
| P10 | 60 | Right |
| P11 | 63 | Right |
| P12 | 67 | Right |
Scatter plot
Blue = No disease · Red = Disease
The highlighted dashed line is the active threshold. Fainter lines show the other candidate midpoints between unique Age values.
Practice
Try It Yourself
Open the practice lab to complete the starter code in the notebook.
Knowledge Check
Quick Quiz
In a threshold split, samples on the left satisfy:
Summary
Key Takeaways
- A threshold split divides samples using feature <= threshold.
- Different thresholds create different left and right groups.
- Each split changes the weighted Gini score.