Lesson 1 of 10 in this unit
Start with a simple baseline.
Fit majority, nearest-neighbor and shallow-tree predictors; compare the same validation cases before adding complexity.
By the end: Explain a baseline, trace a neighbor vote or tree path, and justify model complexity using separate development evidence.
Prerequisites and path options
Why learn this? Find out whether a complicated model adds value over a cheap, understandable reference.
Start with something concrete.
A model makes mistakes. Before building a larger network, ask how often a rule that always predicts the common class would be right. Then inspect whether nearby examples or a few learned questions improve on that reference.
Try the interactive modelA one-neighbor model gets zero training error, including on three flipped labels. What should you inspect next?
Change one thing. Watch what follows.
Loading this browser experiment…
Understand what changed.
A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.
The idea in everyday terms
A baseline is a simple reference that a more complicated model must improve on. Always predicting the most common training class can score well when one class dominates, while missing every case of the other class.
What to watch in the experiment
Fit the reference using training labels, then compare it with neighbors and a small tree on the same development examples. Inspect where each method makes mistakes instead of looking only at the total score.
What this does not establish
The prediction map is an approximate picture of behavior. Reusing these development cases to select settings does not produce an untouched final test or show that a complex model is worth its cost.
Open the full worked examples, calculations and limitations
This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.
Give improvement a reference point
Suppose 80 of 100 examples have label 0. Always predicting 0 would be correct on 80 examples while missing every label-1 case. That baseline is a reference for comparison, not necessarily an acceptable decision. An 81% model has not established much without examining which errors it changes and their costs.
For a classification task, fit a majority baseline from training labels. For a numerical prediction task, a training mean is a useful starting point. Do not use validation labels to decide what your “training majority” was. The lab compares three predictors on identical training and development validation coordinates.
Learn a decision from nearby examples
A nearest-neighbor predictor stores training examples. Given a query, it measures distance to each training input, selects the k closest examples and takes a vote. Here k is a positive whole number, and every selected example receives one vote. Ties between classes choose 0; equal distances use the original training order so results are reproducible.
The map connects the selected query to the examples that vote. Both inputs range from 0 to 1 with equal scale. A query at (0.2, 0.3) and a training input at (0.5, 0.7) differ by 0.3 horizontally and 0.4 vertically:
The square-root symbol reverses squaring: √0.25 = 0.5 because 0.5 × 0.5 = 0.25.
d is the Euclidean distance between two points, in the same coordinate units as the inputs. It is the straight-line length of the displacement. If one input instead used millimetres and the other kilometres, its numerical scale could dominate. In a real pipeline, decide what distance means and fit any scaling only on training data.
With k = 1, one label decides the answer. With larger k, a broader neighborhood votes. A broader neighborhood can reduce sensitivity to one corrupted label while also mixing examples from opposite sides of a real boundary. The vote fraction is not automatically a well-calibrated probability of correctness.
Let a tree ask learned questions
A decision tree partitions the input plane using questions such as “Is x at most 0.625?” Follow the selected query through the questions to reach a leaf. The leaf predicts its training-majority label. This is a fitted tree: it searches candidate cuts using training labels, rather than receiving the underlying synthetic rule.
The lab scores a candidate split by how mixed its two resulting label groups are. Gini impurity for a binary group is 2 × p × (1 − p), where p is its fraction of label-1 examples. A pure group has impurity 0. A half-and-half group has impurity 0.5. The fit weights each child group’s impurity by its example count, then chooses the smallest sum. It considers midpoints between distinct training coordinates, with at least two examples on each side.
Tree depth counts how many questions may appear on a path. More depth can describe a more intricate boundary, but can also carve around unusual or wrong training labels. The lab caps depth at four. Ties use x before y and the lower cut before a higher one. Read the trace alongside the region map: each question corresponds to an axis-aligned division.
Compare the same examples
The 64 training coordinates and 49 validation coordinates are disjoint fixed grids. The data-generating label rule is x + y ≥ 1.05. Models fit only training labels; displaying the rule explains the synthetic exercise, not an implementation that secretly supplies the answer to the predictor. Flipping three training labels changes only those labels. Validation stays fixed.
Training error can be misleading. When measuring a nearest-neighbor model on its own training inputs, each query can retrieve itself. With k = 1, even a flipped label can be reproduced perfectly. Inspect separate validation errors to see whether the model predicts beyond that self-match.
The coarse background samples 400 cell centers; it is a visual approximation of prediction regions. The numerical trace uses the actual query. Use the selected-case control to inspect an error without relying on the plot’s colors or resolution.
Make a bounded choice
Write down the baseline, candidate settings, validation error count and an inspected mistake. Consider storage and prediction cost as well as accuracy: nearest neighbors retains examples and computes distances at query time, while a fitted shallow tree follows only a few questions. Neither architecture is automatically the right choice.
Every time you inspect this validation set to choose a setting, you use development evidence. The page does not contain an untouched final test, and repeated visits are not independent replications. To support a final claim, freeze the choice and evaluate suitable new cases. The real-data audit project adds measurement and split issues; the next regression lesson asks what changes when the output is a number.
A validation query has nearest training labels 0, 1 and 1. An equal-weight three-neighbor classifier predicts what?
Take this idea with you.
Keep a simple reference, compare on the same separate examples and inspect individual errors. More neighbors or deeper trees change assumptions; neither is automatically better.
Explore related topics and the topic map
How this topic connects
Explore this topic on the interactive mapUse these connections to review a foundation or choose where to go next. You can open any topic without completing the others.
What it builds on
- Define the task
Turn a vague request to use AI into a prediction task with a useful outcome you can measure.
- Data quality and leakage
Repair a dataset without letting answers leak into training and make evaluation look better than it is.
- Decision metrics
Choose when to act on a prediction by comparing the consequences of different kinds of error.
Fit majority, nearest-neighbor and shallow-tree predictors; compare the same validation cases before adding complexity.
What it enables
- Fit a line and explain its errors
Estimate a numerical outcome and inspect its errors before assuming a straight-line relationship is adequate.
- Combine many imperfect trees
Understand why combining trees can help and when their shared mistakes still limit the result.
- Find structure without labels
Explore groups and compressed views without mistaking geometric patterns for verified categories.
Show 1 more connections
- Validate without reusing the answers
Choose an evaluation split that reflects groups and time so the score answers the intended question.