02 · See it in action
Follow the steps
- Draw a two-question rule for a synthetic task.
- Fit a shallow tree and inspect its splits.
- Compare it with a deeper tree on held-out data.
- Look at the number of examples reaching each leaf.
Worked example
from sklearn.tree import DecisionTreeClassifier
x = [[10], [15], [40], [45]]
y = [1, 1, 0, 0]
m = DecisionTreeClassifier(max_depth=1, random_state=7).fit(x, y)
print(m.predict([[12], [42]])) # [1 0]
Read the example once, then explain each part aloud in your own words. If it includes Python, you can understand the idea first and run the code later in a local Python environment. Code is shown as text; this page does not execute it.
Sign in to save your reading progress.
Sign in