Supervised Learning
Theme
Palette
Download
Caption (tap to copy)
📖 Deep dive (full written explanation)
This post is the mechanical core of the day. The previous posts established what supervised learning is and why it matters; this one explains how a model actually learns from labeled data. The thesis is liberating: behind the intimidating zoo of algorithms is one repeating idea — a feedback loop of guess, measure, adjust.
Framing it as a loop demystifies the whole field. Linear regression, logistic regression, neural networks, and gradient-boosted trees differ in the shape of the model and the details of the steps, but they all hill-climb toward lower error using the same four ingredients introduced here.
A model, mechanically, is just a function with adjustable numbers called parameters or weights. Linear regression has two: a slope and an intercept. A deep network has millions. Training is nothing more than searching for the parameter values that make the model's outputs agree with the known labels as closely as the model's shape allows.
This 'guesser with knobs' framing is powerful because it unifies simple and complex models. The difference between a textbook line-fit and a giant network is the number of knobs and how they're wired, not the nature of the task. In both cases you're turning knobs to reduce a measure of error.
The loss function is the scorekeeper. It collapses 'how wrong are these predictions' into a single number you can minimize. For regression, mean squared error averages the squared gaps between predictions and truth, punishing large misses heavily. For classification, cross-entropy measures how far the predicted probabilities are from the actual classes.
Choosing the right loss matters because it defines what 'good' means to the optimizer. The model will ruthlessly minimize whatever loss you give it, so the loss must encode what you actually care about. A mismatch between your loss and your real objective is a subtle, common source of disappointing models.
The cycle diagram is the heart of the post: predict, measure loss, compute the gradient, update the weights, then repeat. This loop runs anywhere from a handful of times for a simple model to millions of iterations for a large network. Each pass nudges the parameters toward lower loss.
Seeing it as a cycle rather than a one-shot calculation is the key insight. Learning is iterative refinement, not a closed-form answer dropped from the sky. Every supervised algorithm you'll meet is some specialization of this loop, which is why internalizing it pays off across the entire field.
Gradient descent is the engine that drives the loop. The gradient is a vector that points in the direction of steepest increase of the loss; its negative points downhill, toward lower error. You take a small step in that downhill direction, with the step size controlled by the learning rate, then recompute and step again.
The mountain analogy is apt: imagine standing on a foggy hillside of error and feeling which way is down, then taking a careful step. Too large a learning rate and you overshoot the valley; too small and training crawls. Tuning that single number is one of the most consequential knobs in practice.
This pseudocode makes the loop literal. You start with random weights, then for a fixed number of epochs you predict on the training data, compute the loss against the true labels, calculate the gradient of that loss with respect to the weights, and step the weights in the downhill direction scaled by the learning rate.
Real frameworks add momentum, adaptive learning rates, mini-batches, and automatic differentiation, but the skeleton is exactly this. When you call model.fit in scikit-learn or run a training loop in PyTorch, some elaborated version of these six lines is what executes underneath.
Data splitting is the discipline that keeps you honest. Because a flexible model can simply memorize its training data, evaluating it on that same data tells you nothing about real performance. The standard remedy is a three-way split: train to fit the weights, validation to tune choices and detect overfitting, and test as a final untouched exam.
The test set is sacred. You look at it once, at the very end, to estimate real-world performance. Peeking at it repeatedly to guide decisions quietly turns it into a second validation set and inflates your reported numbers — a mistake the fifth post warns about explicitly.
The stacked diagram visualizes the three roles. Training data does the heavy lifting of fitting parameters. Validation data is consulted repeatedly to pick hyperparameters, compare models, and watch for the moment overfitting begins. Test data sits sealed until the end and is used exactly once for an honest final score.
The ordering and the one-use rule for the test set are not bureaucracy — they're what make your performance estimate trustworthy. Every time information from later sets leaks earlier, your numbers drift optimistic and your production surprise grows. The separation is the safeguard.
Overfitting and underfitting are the two ways a model misses generalization. An overfit model is too flexible: it memorizes the training data including its noise, scoring beautifully on train and poorly on test. An underfit model is too rigid: it can't capture the real signal, scoring poorly on both. The art is landing between them.
The practical fixes diverge. For overfitting, gather more data, simplify the model, add regularization, or stop training early. For underfitting, use a richer model or better features. Diagnosing which problem you have — by comparing train and test scores — tells you which lever to pull.
This slide names the actual target of the whole enterprise: generalization, meaning low error on data the model has never seen. Low training loss is necessary but cheap; any sufficiently flexible model can drive it to zero by memorizing. What you want is performance that transfers to new cases.
The operational signal is the gap between training and validation loss over time. As long as both fall together, learning is healthy. When validation loss bottoms out and starts rising while training loss keeps dropping, the model has begun memorizing noise — that inflection point is your cue to stop early or add regularization.
The pipeline diagram assembles the full fitting process end to end: split the data, initialize the model with random weights, run the training loop of loss-and-gradient steps, then evaluate once on the held-out test set. It connects the individual concepts into the workflow you'll actually execute.
Laying it out as a pipeline also previews the code post. Each stage here maps almost one-to-one onto a scikit-learn call — train_test_split, instantiate a model, fit, and score — so the abstract mechanics and the concrete API line up cleanly.
The closing tips distill the post to four reusable parts plus the guardrail. The model is a parameterized guesser; the loss turns wrongness into one number; the gradient gives the downhill direction; the optimizer takes the steps. Validation, the fifth item, is what keeps the whole loop honest about generalization.
Commit these to memory and any new algorithm becomes legible. When you read about a novel method, you can immediately ask: what's the model's form, what loss does it minimize, how does it compute updates, and how is generalization controlled. Those four questions decode almost anything in supervised learning.
The cover positions this as the engine-room post, the technical heart of the arc. It deliberately trades the breadth of the motivation post for depth on the single mechanism — the training loop — that underlies every supervised method.
The teaser hands off to the code post, where these abstractions become a runnable scikit-learn build. Having seen the loop in pseudocode and diagrams, you'll next watch it execute on real data with a real classifier and an honest accuracy score.