Machine learning, explained
Machine Learning
You already know how to write a normal computer program. You describe the rules, and the computer follows them. If a number is greater than ten, print one message. If it is not, print another. You provide the rules, and the program produces an answer.
Machine learning starts at the other end. You provide examples and the answers you wanted, then let a computer find a set of rules that works well on those examples. In ordinary programming, rules plus data produce answers. In machine learning, data plus answers produce rules. Those learned rules are then used on new data.
That inversion sounds mysterious only until you break it into parts. You need data to show the system what the world looks like, a model to hold possible rules, a loss to measure mistakes, and an updating process to reduce those mistakes. Then you need tests that answer a harder question: did the system learn something general, or did it merely remember its examples?
Examples become a usable prediction
Learning adjusts a model with known examples, then inference applies the adjusted model to new input.
- Data Examples and, when needed, their answers.
- Model A flexible set of possible rules.
- Loss A score for how far a prediction is from the answer.
- Training Repeated adjustment using the loss.
- Inference A prediction for input the model has not seen before.
Data: the examples the machine can see
Imagine teaching a child to sort laundry. You put a shirt in one pile, a towel in another, and keep showing examples until the difference becomes clear. The child can learn only from what you show and what you call each thing. A box of well-labelled clothes gives a better lesson than a box of mixed clothes with half the labels missing.
In machine learning, data means the examples available to the system. An example might be a photograph, a sentence, a sound clip, a row of measurements or a record of a past decision. The individual pieces of an example are often called features. A photo has pixels. A house record might have floor area, location and age. In supervised learning, each example also has a label, such as "cat", "not cat", or a known sale price.
Data is not a neutral bucket. It carries the choices made while collecting it: what was measured, what was ignored, who was represented and how labels were assigned. A model trained on old decisions can learn old preferences as if they were facts. More examples do not automatically repair a narrow or poorly labelled collection. The machine sees the evidence you give it, not the reality you meant to give it.
Try this: label ten photos from your own camera roll with one simple rule, such as indoor or outdoor. Write down what visible clues you used. Then ask what a machine would need to see to make the same decision, and which of your clues are missing from the images.
Model: a shape for possible rules
Think of a model as a recipe with adjustable quantities. A cake recipe may say two cups of flour and one cup of milk, but you can adjust those amounts until the cake has the texture you want. The recipe gives you a shape for making cakes. The quantities determine this particular cake.
A machine learning model is a mathematical structure that can turn input into an output. It contains adjustable values called parameters. For a simple model predicting a house price, one parameter might describe how much price tends to change with floor area. Another might account for a baseline price. A larger model may have millions or billions of parameters arranged in layers, but the basic idea remains: input goes in, adjustable computation happens, and a prediction comes out.
A model is not the same thing as the data it learned from. Data supplies examples. The model supplies a place where patterns can be represented. A very rigid model may miss a real pattern. A very flexible model may fit every odd detail in its examples. Choosing a model is therefore choosing what kinds of relationships the system is able to express, not choosing a magic container for truth.
Try this: draw a straight line through a scatter of ten dots on paper. Now draw a wavy line that touches every dot. Explain back which line would be safer for predicting another dot, and why flexibility can help or hurt.
Loss: a score for being wrong
Imagine playing golf with one goal: finish each hole in as few strokes as possible. Your score tells you how well you did, but it does not by itself tell you how to swing. It gives you a number that lets you compare one attempt with another.
Loss is that score for a machine learning model. It measures the gap between a prediction and the known answer. If a model predicts a house costs 300,000 and the recorded price is 320,000, a loss function turns that gap into a number. Different tasks use different loss functions. A classification task may penalise a wrong category. A numeric prediction may penalise the size of the error. Some losses penalise large mistakes much more heavily than small ones.
The loss is a design choice, so it quietly states what counts as bad. A spam filter that treats a missed scam and a blocked family email as equally costly is using a simple rule that may not match your real concern. The model does not understand your intention behind the score. It responds to the score you give it. If the score rewards the wrong shortcut, training can make the wrong behaviour more consistent.
Try this: make five guesses about the weight of five ordinary objects. Compute each error in your head, then rank the guesses using two rules: raw error and squared error. Notice which mistake each scoring rule makes look most serious.
Gradient descent: adjust by feeling the slope
Picture yourself on a dark hillside. You want to reach the lowest point, but you cannot see the valley. You take a small step, feel whether the ground rises or falls, then choose a direction that seems downhill. Repeat that enough times and you may reach a low place, though rough ground or a misleading dip can complicate the walk.
Gradient descent is the precise term for a related update method. The model has parameters, and the loss changes when those parameters change. The gradient describes the direction in which loss rises fastest for a small change. Gradient descent moves the parameters in the opposite direction, by a chosen step size called the learning rate. The aim is to lower loss.
The analogy has limits. A real training process may calculate gradients across many parameters at once, using batches of examples. It may settle in a shallow local low point, move too slowly, or jump past a useful point if its learning rate is too large. Lower training loss is useful evidence, not a guarantee that the model understands the task.
Try this: draw a bowl-shaped curve and place a coin somewhere on it. Move the coin toward the bottom using only small moves and the local slope. Then repeat with large moves. Explain back why step size changes whether you settle, wander or overshoot.
Training: repeated correction
Learning to throw a ball is repeated practice with feedback. You throw, see where the ball lands, change your motion, and try again. One throw is not training. A pattern of attempts and corrections is.
In machine learning, training is the process of showing a model data, producing predictions, calculating loss, and adjusting its parameters. One pass through the training examples is called an epoch. Often the system works with a small batch at a time, which makes updates practical and introduces useful variation into the process. Training continues until a stopping rule says the model has made enough progress, stopped improving, or reached a resource limit.
Training does not mean the model receives a lesson in the human sense. It does not form a verbal explanation of why an example matters. It changes numerical parameters in response to an objective. The human work remains important: choosing the task, preparing examples, selecting a loss, setting the update process and deciding what evidence counts as enough.
Try this: use a spreadsheet with ten points and fit a straight line by changing its slope and intercept. After each change, calculate the total squared error. Keep a short log of which change lowered the score and which did not. You are making training visible.
Generalization: work beyond the examples
Suppose you practise a speech in one quiet room. You remember every pause, every chair and the exact pattern of light on the wall. If you can still give the speech in a noisy room to people sitting somewhere else, you have learned more than the rehearsal. You have learned a pattern that travels.
Generalization is a model's ability to perform well on new examples that were not used to adjust its parameters. This is the point of machine learning. A model that performs well only on its training examples has memorised details rather than learned a useful relationship.
The common failure is overfitting. A model becomes so responsive to the training data that it also learns noise, quirks and accidental clues. A student who memorises the answers in one practice test may score well on that exact sheet and poorly on a new set of questions. More parameters can make a model more capable, but capability does not remove the need for fresh evidence. Data that resembles future use matters too. A random split can hide a time change, a new population or a duplicate record.
Try this: create a ten-question quiz about a subject you know. Study the answer key, then write five new questions that test the same ideas with different wording. Explain back why success on the first sheet is not enough evidence of generalization.
Evaluation: test the claim on held-back evidence
You would not judge a driving student only by watching them practise the same route with the instructor giving every turn. You would also observe a different route and check whether they can drive safely without the hints. That second observation tests the claim you actually care about.
Evaluation measures how a trained model performs against data held back from parameter updates. A test set is a collection reserved for a final estimate of performance. A validation set can help choose settings during development. The names matter less than the boundary: evidence used to tune the model should not be presented as independent proof that the tuned model works on new cases.
A single score is rarely enough. Accuracy can hide a model that misses a rare but important class. Precision asks how often positive predictions are correct. Recall asks how many real positives were found. A useful evaluation also checks slices of the data, failure examples, calibration, speed and the cost of mistakes in the real setting. Evaluation is where a technical result meets a human consequence.
Try this: make a two by two table for ten predictions about whether an email is spam. Count correct spam calls, missed spam, correct ordinary mail and blocked ordinary mail. Explain back why one total accuracy number does not show which kind of mistake you should investigate.
Inference: use the trained model
After practising a route, a driver uses what they learned when a new trip begins. The practice changed their ability. The trip is a separate event: they receive new surroundings and make decisions from that learned skill.
Inference is the act of running new input through a trained model to produce a prediction or other output. A photo classifier receives a new photo and returns probabilities for its categories. A language model receives a sequence of tokens and calculates likely next tokens. Inference uses the model's current parameters. It is not the same process as training, even when the same hardware and mathematical operations are involved.
Inference can fail for reasons that training metrics never exposed. The camera may change, the language may shift, the input may be incomplete, or the new case may belong to a group missing from the original data. This is called distribution shift: the world that produces new inputs no longer matches the world represented by the training examples. A prediction is an output from a learned relationship, not a certificate that the relationship applies here.
Try this: take one rule you use to sort your ten labelled photos and apply it to five photos from a friend or a public image collection. Record any case where your rule feels uncertain. Explain back what new evidence you would collect before trusting a model on that kind of input.
You now have the whole small vocabulary. Data gives examples. A model represents possible rules. Loss scores mistakes. Gradient descent changes parameters to lower that score. Training repeats the correction. Evaluation checks held-back evidence. Generalization asks whether the pattern travels. Inference uses the trained result on a new case.
Train something tiny this week. A spreadsheet can predict a number. Ten labelled photos can support a simple sorting experiment. Keep the task small enough that you can inspect every example and every mistake. Then explain the result back to yourself in plain words: what did the data show, what rule did the model learn, what did loss reward, and what happened on examples it had not seen? That explanation is the beginning of understanding machine learning.