Click to add labeled points, then build a decision tree and watch it split the space to separate classes.
Click on the chart to add a point of the selected class.
A decision tree works by repeatedly asking yes/no questions about the data, "is feature x greater than 5.2?", each question splits the current set of points into two groups, and the tree keeps splitting recursively until it reaches a stopping condition (maximum depth, or a group that's already pure, containing only one class). The colored regions in the visualization above show exactly what the tree has learned, each rectangular region represents a leaf, a final decision, colored by which class the tree predicts for any point falling in that region.
At every potential split, the tree needs a way to decide which question is "best." This visualization uses Gini impurity, a measure of how mixed the classes are within a group, 0 means perfectly pure (all one class), 0.5 means maximally mixed (50/50 split between two classes) for a two-class problem. At each step, the algorithm tries many possible split points across every feature and picks whichever split produces the lowest weighted average Gini impurity across the resulting two groups, in other words, whichever question does the best job of separating the classes.
Increase the max depth slider and watch the tree carve out increasingly small, specific regions, eventually isolating individual points or small clusters of noise. This is overfitting made visually obvious, a very deep tree achieves high accuracy on the exact training points shown, but it's memorizing quirks of this specific dataset rather than learning a genuine underlying pattern, and it will likely perform poorly on new points it hasn't seen. A shallower tree captures the broad, genuine pattern in the data while ignoring noise, generally generalizing better to new data even though its training accuracy looks lower.
Unlike neural networks, a decision tree's decisions are directly interpretable, you can trace the exact sequence of questions that led to any prediction, which matters enormously in domains requiring explainability, like credit decisions or medical diagnosis support, where "the model said so" isn't an acceptable answer. Single decision trees are also the building block for more powerful ensemble methods, Random Forests average predictions from many trees trained on random subsets of data, and Gradient Boosted Trees (like XGBoost) build trees sequentially, each one correcting errors from the previous, both routinely outperforming single trees while retaining much of their interpretability advantage.