Visual explainer
What Is Machine Learning?
Machine learning fits patterns from data. Follow a toy classifier from labelled examples to a held-out test and see why memorization fails.
Machine learning fits patterns from examples to perform a task. In supervised learning, training uses inputs paired with supplied answers; prediction applies the fitted model to new inputs. This page follows one deliberately tiny classifier through both steps.
The two silhouettes are both cats. A toy rule accepts only two visible ears, so the hidden ear causes rejection. Learning offers another approach, but still depends on suitable features, examples and evaluation. It does not automatically outperform a written rule.
Pair Features With Answers
Each row is an example. The two numerical features, x1 and x2, are inputs; the circle or triangle is a supplied target: circle means cat, triangle means dog. IDs track examples and are not model inputs. These are synthetic, unitless features, not measurements extracted from the pictured ears or actual photographs.
Our training rows are A=(1,1), B=(1,2), C=(3,3), and D=(3,2). A and B are cats; C and D are dogs. This input-matrix and target-vector distinction follows scikit-learn's fitting and prediction model.
Reserve Unseen Examples
Separate all eight examples before fitting. Only A–D enter the fit route; E–H stay outside it. The dashed enclosure marks held-out data. Keep its answers out of parameter choice and any fitted preprocessing.
This split is a teaching device, not a recommended four-row training set. In a real model-selection workflow, use validation data or cross-validation for tuning and reserve a final test set. Related people or future observations may require group-aware or chronological splits. See model evaluation.
Try A Candidate Rule
We choose the model family first: predict dog when x1+x2 is at least a threshold t; otherwise predict cat. Training will choose t. The axes show feature values from 0 to 4, at 50 drawing units per feature unit. Point shapes always show the true class.
At t=2, all four sums (2,3,6,5) predict dog. Both cats are mistakes, marked with crosses. A lies exactly on the line and counts as dog because the comparison includes equality. This is a separating boundary, not a regression line fitted through points.
Let The Objective Choose
Try just three candidates. Thresholds 2, 4 and 6 make 2, 0 and 1 training mistakes respectively. At 6, D's sum of 5 predicts cat incorrectly, while C's sum of 6 still predicts dog. Bar lengths use 90 drawing units per mistake; the ring at zero is a marker, not a positive-length bar.
Minimizing that training error selects t=4. This finite search is our entire training algorithm. Other algorithms optimize other objectives and may search many parameters; the example does not imply that every model learns by trying three thresholds.
Freeze The Learned Boundary
The line now joins (0,4) to (4,0), with exactly the same axes as before. Both circles fall below it and both triangles above it. The model gets 4/4 training labels right. That result describes the examples used to select the model, so it is not evidence of future accuracy.
Apply It Without Fitting Again
E has features (0.5,1). This scene changes representation from two-dimensional positions to bar heights: each bar uses 50 drawing units per feature unit, measured upward from one baseline. Adding 0.5 and 1 gives 1.5, below the dashed threshold at 4. The unchanged model predicts cat. It does not need E's answer to make that prediction.
Check Against Held-Out Answers
Return to the original feature axes. E=(0.5,1), F=(2,3), G=(3,3.5), and H=(2.5,2) have true labels cat, dog, dog, cat. Their sums are 1.5, 5, 6.5 and 4.5; the model predicts cat, dog, dog, dog. H is the crossed circle on the dog side.
Accuracy is 3/4 = 75%, using the fraction of matching labels. This tiny synthetic score establishes no population-level performance guarantee. A train/test gap alone does not uniquely diagnose memorization.
Change The Learning Signal
Remove the targets from A–D. All points now use identical dots at their original feature coordinates. Nearby pairs suggest two groups, outlined schematically; these envelopes are not the output of a specified clustering algorithm. An unsupervised grouping can expose structure, but cannot supply the meanings “cat” and “dog” without additional information. Supervised classification is one learning setting, not the definition of all machine learning.
Where It Breaks
Replace the feature rule with a table that stores only A–D and their labels. It returns all four stored answers correctly, yet has no entry for E–H. Question marks are abstentions: zero of four new inputs are answered. That is zero coverage, not a measured zero-percent classification accuracy. Perfect recall cannot establish generalization, the issue illustrated in scikit-learn's holdout guidance.
The learned threshold also has limits: it cannot represent every possible class boundary, and different or shifted data can invalidate its apparent success. Features, fitting and evaluation must match the intended task.
The Quick Version
- Supervised learning fits a prediction rule from inputs and supplied targets.
- Reserve evaluation data before fitting or selecting model settings.
- Training chooses t=4 with zero mistakes on four examples.
- Prediction applies that fixed rule without retraining.
- Three held-out successes and one miss give 75% toy accuracy.
- Unsupervised structure does not provide semantic class names for free.
- Perfect training recall can coexist with zero coverage of new IDs.