Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 05 / Topic 4 of 7

Decision trees

A decision tree asks yes/no questions ("tenure < 12?") and routes each row down to a leaf with a prediction. Trees are readable and need no scaling — but grown without limits they memorise the training set:

deep = DecisionTreeClassifier(random_state=0)             # no depth limit
shallow = DecisionTreeClassifier(max_depth=4, random_state=0)
# on digits: deep train 1.0 test 0.878 <- memorised, then stumbles
#            depth 4 train 0.576 test 0.569 <- too simple for 10 classes

Perfect training accuracy with a test drop is the overfitting signature (more in Part 6). A single tree is rarely the final model — but it is the building block of the next two.

🧪 Quick quiz

  1. A tree scores 1.0 on training data and 0.878 on test data. What happened?
Show the answer

It overfitted — with no depth limit it memorised the training set. Limit depth, prune, or use an ensemble.

Done here? The practice set for Part 5 — 4 exercises with solutions — is on the part page.

Search the guide