AI & Machine Learning ★★☆ Moderate

🌲 Decision Tree — CART & Gini Impurity

Build and visualise a CART decision tree step-by-step. Watch the algorithm minimise Gini impurity G = 1−Σpᵢ² at each split, see the decision boundary emerge, and compare tree depth vs accuracy trade-off.

3
5
100
Nodes: Leaves: Depth: Accuracy: Root Gini:

Starting…

Generating dataset. The CART algorithm finds axis-aligned splits that minimise Gini impurity at each node. Nodes are revealed one by one.

The Physics

CART split criterion: Gini(S) = 1 − Σᵢ pᵢ². Best split minimises weighted child impurity: ΔGini = Gini(parent) − (|L|/|S|)·Gini(L) − (|R|/|S|)·Gini(R). Tree grows until max_depth or min_samples_leaf. Pruning via cost-complexity α·|leaves|. Feature importance = total Gini reduction attributed to each feature across all splits.