Splitting space, one question at a time
Method
Generate points, pick a depth and a splitting criterion, then watch the classifier recursively carve the plane into class regions. Built to make the algorithm visible.
Decision Tree Classifier Visualizer
How Decision Trees Work
Decision trees split data recursively based on feature values to maximizeGini impurity reduction.
Each split creates a decision boundary. The tree stops when:
- All samples have the same label
- Maximum depth (3) is reached
- Too few samples remain (≤ 2)
- No further information gain is possible
How decision trees work
Decision trees are supervised learning algorithms used for both classification and regression. They work by recursively splitting the dataset on feature values, each time choosing the split that maximizes information gain or minimizes impurity, until a stopping condition is met.
Splitting criteria
Gini impurity measures the probability of incorrectly classifying a randomly chosen element. Entropy / information gain measures the reduction in uncertainty after a split. At each node the tree chooses the feature and threshold that improve the chosen measure the most.
Decision boundaries
Each split creates a hyperplane — a vertical or horizontal line in 2D — that separates the feature space. Stack enough of them and the final decision boundary becomes piecewise constant: a mosaic of rectangles, each labeled with a single class.
Using the visualizer
Generate random or linearly separable data, set the maximum depth and splitting criterion, then build the tree step by step or all at once. Watch how the boundaries form and how the tree structure evolves as depth increases.
What is a decision tree?+
A decision tree is a supervised machine-learning model that classifies data by asking a sequence of yes/no questions about feature values. Each question splits the data, and the splits stack up into a tree whose leaves are predictions.
What is the difference between Gini impurity and entropy?+
Both measure how mixed the classes are in a group of points. Gini impurity estimates the chance of mislabeling a randomly chosen element; entropy measures uncertainty in bits. The tree picks the split that lowers the chosen measure the most. They usually produce similar trees.
What does maximum depth control?+
Depth is how many questions deep the tree can go. Shallow trees are simpler and generalize better; deep trees fit the training data tightly and can overfit. Lowering the depth here shows the decision boundary getting coarser.
What are decision boundaries?+
In 2D, every split is a vertical or horizontal line. Together they tile the plane into rectangles, each assigned to one class. That piecewise-constant pattern is the decision boundary you see fill in as the tree grows.
When does the tree stop splitting?+
When it hits the maximum depth, runs out of useful splits (no further information gain), reaches a minimum number of samples in a leaf, or a group becomes pure (all one class).