ML Playground
ClassificationIntermediateSupervised learning

Decision tree

Available

Visualize how the data space gets split and how the tree grows in parallel.

Description

Qué haceClassifies by asking a series of simple yes/no questions about the data (is this variable greater than X?), like an automatically learned flowchart.

Para qué sirveWhen the model needs to be interpretable — able to explain its decision as a sequence of readable rules — and the data has class boundaries that aren't straight lines.

Splits the feature space into rectangles using questions like is x ≤ threshold?. Synthetic dataset.

How the tree grows

Gini impurity

1 − Σ pᵢ²

How mixed a node's classes are. 0 is pure; close to 1 is a total balance.

Gain

The parent's impurity minus the weighted average of the children. The threshold with the highest gain is chosen, trying every feature.

Recursion and leaves

Each child repeats the process. A node becomes a leaf when it's pure, reaches the maximum depth, or runs out of enough points.

Ensemble (bagging)

The optional section combines several trees over bootstrap samples, voting the majority class among all of them.

Out of scope for this demo:Post-construction pruning — trimming subtrees that don’t improve validation — isn’t implemented; size is only controlled via maxDepth.

What each metric shows

Prediction / depth used

The class of the leaf the query falls into, and the actual depth built (can be less than the maximum).

Leaves

The number of rectangular regions the space ended up split into.

Not generalization:Training accuracy only measures the points used to build the tree — a deep tree can memorize them and reach 100% without saying anything about new data (see fundamentals).

Strengths and limits

Interpretable

Every prediction is explained as a short sequence of questions, with no need to scale features.

Overfitting

Without limits, it can isolate every point in its own leaf — see the “Excessive depth” case.

Unstable

A small change in the data can change the entire structure — see “Instability from a small change.”

Right-angle boundaries

Separating diagonal or circular boundaries requires many splits — see “Concentric circles.”

Playground

Training points and tree regions-6.3-3.00.33.77.0-7.2-3.8-0.33.16.5xy
120 training points across 3 classes, split into 4 regions. The query point (0.00, 0.00) falls in the class 0 region.
  • Class 0
  • Class 1
  • Class 2
  • Query point

Each rectangle is a real leaf of the tree, not a sampled approximation: its edges are exactly the splits CART chose. The region containing the query point is highlighted with an accent border.

Classification result

Prediction
Class 0
Depth used
2 / 3

Can be less than the maximum depth if the tree already separated everything earlier.

Leaves
4
Training accuracy
100%

Over the same points used to build the tree: it doesn't measure generalization.

Tree structure

The nodes highlighted in accent are the path the query point follows, from root to leaf.

y-0.98

Gini 0.667 · n = 120 · gain 0.321

If y ≤ -0.98

x-3.14

Gini 0.048 · n = 41 · gain 0.048

If x ≤ -3.14

Leaf · prediction: class 0

Gini 0.000 · n = 1

  • Class 0: 1 (100%)

If x > -3.14

Leaf · prediction: class 2

Gini 0.000 · n = 40

  • Class 2: 40 (100%)

If y > -0.98

x0.47

Gini 0.500 · n = 79 · gain 0.500

If x ≤ 0.47

Leaf · prediction: class 0

Gini 0.000 · n = 39

  • Class 0: 39 (100%)

If x > 0.47

Leaf · prediction: class 1

Gini 0.000 · n = 40

  • Class 1: 40 (100%)

Dataset generation

Changing these controls generates a new synthetic dataset and rebuilds the tree.

Seed for the deterministic generator.

40
5120
1.2

Standard deviation of each group's Gaussian noise.

0.24.0

Tree hyperparameters

3

The maximum number of split levels the tree can have.

110
4

A node with fewer points than this minimum becomes a leaf even if it's impure.

240

Ensemble (bagging)

Builds several trees over bootstrap samples of the same dataset and combines their predictions by majority vote.

Query point

Educational cases

Related concepts

References