Summary - Decision trees
- Machine Learning course
- Beginner
- Lesson 58/112
- 6 min
In this group you learned decision trees, splitting criteria, and overfitting.
Summary: decision trees
In this group:
- A tree splits data with yes/no questions; leaves decide and the rules are read with
export_text. - Splits are chosen with Gini (default) or entropy.
max_depth,min_samples_leaf,ccp_alphalimit the tree.- An unlimited tree overfits; the training-test gap is the sign.
- No scaling is needed;
feature_importances_gives feature contributions.
The instability of single trees is fixed by random forest and boosting, which you'll see later.
Practice Tree regression
Train a DecisionTreeRegressor(max_depth=1). Because there is a single split there are only two distinct predictions; print the predictions for [[2], [8]].
Starter code
from sklearn.tree import DecisionTreeRegressor
X = [[1], [2], [3], [7], [8], [9]]
y = [10, 12, 11, 30, 32, 31]
# buraya yazSample solution
from sklearn.tree import DecisionTreeRegressor
X = [[1], [2], [3], [7], [8], [9]]
y = [10, 12, 11, 30, 32, 31]
m = DecisionTreeRegressor(max_depth=1).fit(X, y)
print(m.predict([[2], [8]]))Expected output
[11. 31.]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which model doesn't need scaling?
- Every distance-based model
- Decision tree Correct answer
- KNN
- Ridge without scaling
Explanation: A tree compares each feature with its own threshold; units don't change the decision.
2 Require at least 5 examples in every leaf.
m = DecisionTreeClassifier(____=5)
m = DecisionTreeClassifier(min_samples_leaf=5)
Explanation: min_samples_leaf prevents small, over-specialised leaves.
3 Match the concepts.
| Term | Meaning |
|---|---|
Gini |
Impurity measure |
export_text |
Prints the rules |
ccp_alpha |
Pruning strength |
DecisionTreeRegressor |
Mean at the leaf |