POST 1 of 5 MorningAI/MLConcept
A decision tree is a flowchart you trained
📅 Day 39. Decision trees are the most interpretable model in ML — and they're also the building blocks of random forests and gradient boosting, which dominate tabular data.
🌳 The model — a flowchart. Each internal node tests one feature against a threshold ('age > 35?'). Branches lead to subtrees based on the answer. Each leaf has a prediction (a class for classification; a number for regression).
🎯 Training — pick the split (feature + threshold) that reduces 'impurity' the most. Recurse on each child. Stop when the tree is deep enough or splits don't help. Greedy, top-down. O(n × d × log n) or so.
📐 Impurity for classification — Gini or entropy. Both measure how mixed the classes are at a node. Pure node (all one class) → impurity 0. Mixed node (50/50) → impurity max. The split that maximises 'parent impurity minus weighted child impurities' is chosen.
📐 Impurity for regression — mean squared error. The split that minimises sum-of-squared-residuals across the children.
🎯 Inference — start at the root, follow branches based on the input's features, return the leaf's prediction. O(depth) time. For balanced trees, that's O(log n).
💎 Why people love decision trees:
→ Interpretable. You can literally print the tree and read it. Every prediction has a traceable path.
→ No scaling needed. Trees handle raw features fine. No StandardScaler. Categorical features (after encoding) work natively.
→ Capture non-linear interactions for free. The tree splits on whichever feature reduces impurity most; if interactions matter, splits naturally exploit them.
⚠️ Why alone they overfit — a deep tree memorises training data. That's why we ensemble them (tomorrow).
💡 Master the building block. Then we stack.#MachineLearning#scikitlearn#Python#AI#100DaysOfCode#DecisionTree