Machine Learning

How a model improves from examples: labels, features, training, and the difference between fitting data and predicting on new data.

What Is Learning?

A machine learning model is just a function that gets better at its job through repeated correction.

Machine learning is the second of the four rings laid out in Artificial Intelligence (AI) — the one where the data writes the function. This page narrows to a single house price and walks it from a useless first guess to a sensible one.

What is machine learning?

Machine learning is the second ring: the one where you supply examples instead of rules, and a training procedure picks the numbers inside the function for you.

You would not reach for it if you could simply write the rule. You reach for it when the rule is one you cannot write down. Describe, in code, what makes a photo a cat — not the word, the actual test on the pixels. Or write the rule that prices a house in a market that moves every quarter. You know the answer when you see it, which is a different thing from knowing the rule, and examples are how you cash that difference in.

The trade is fixed: you give up authorship of the rule, and in exchange you get a rule you could not have authored. What you owe in return is three things — examples, a way to measure being wrong, and a way to adjust. The rest of this page is those three things, in order.

It is not a lookup table. A trained model does not keep the houses you showed it. It keeps a handful of numbers that happen to fit them, which is what lets it answer for a house nobody has ever priced — and also what lets it be confidently wrong about one.

One split comes before all the mechanics, though, because it decides what the mechanics can even be: what the world tells you after each guess.

Types of learning

Machine learning splits into three families, and they differ in one thing only — what comes back after the model has had a go. Get an exact answer and the error is a subtraction. Get a verdict and you have to work out which decision earned it. Get nothing and there is no error at all.

Machine learningwhat do you get back?Supervisedthe right answersUnsupervisedno answers givenReinforcementtrial and errorClassificationpicks a labelRegressionguesses a number

Supervised — you are told the answer

Every training house arrives with the price it actually sold for. Guess, subtract, and the error falls out directly, which is why this is where nearly everyone starts. The catch is that somebody has to produce those answers: sold houses come with prices for free, but a thousand X-rays marked healthy or not means paying a radiologist a thousand times.

It splits again by the shape of the answer you want back.

Classification — picks a label

“Will this house sell within thirty days — yes or no?” The answer is one of a fixed set, so there is no such thing as slightly wrong. You picked the right box or you did not.

Regression — guesses a number

“What will this house sell for?” The answer sits on a scale, so wrong has a size: out by a thousand and out by a million are both wrong, and one of them matters far more. Everything below this section is regression.

Unsupervised — you are told nothing

A pile of houses and no prices at all. The model can still find structure: these four hundred sit together and look nothing like those two hundred. Grouping like that is clustering. The catch is that nobody says which grouping is right, so there is no error to shrink — you judge it by whether it turns out to be useful to somebody downstream.

Reinforcement — you are told how it went

No price attached, just a verdict. Set an asking price, wait, and find out whether the place sold and for how much. Choices that led to a better outcome get made more often. The catch is timing: the verdict arrives long after the decision that earned it, so the model has to work out which of its moves deserves the credit.

These are not stages and they are not ranked — nobody graduates from supervised to reinforcement. They are three situations you can find yourself in, and which one you are in was settled by your data before you wrote a line of code.

The rest of this page lives in one box. Supervised, regression, one house at a time: the smallest version there is. Everything you see from here — parameters, a prediction, feedback — is present in all three families. Only where the feedback comes from changes.

A model is a function

Start with the shape, because it never changes. A model looks like any function you have ever used: something goes in, something comes out.

A photo goes in, the word “cat” comes out. A house’s square footage goes in, a price comes out. An email goes in, “spam” or “not spam” comes out. The only difference between a model and the functions you already write is that you did not choose what sits in the middle box — training did. And nothing about the shape changes as models get bigger: one with a billion numbers inside it still takes an input and returns an output.

Inputa photo of a catFunctionthe modelOutput“cat”

A running example: guessing a house price

We will keep one example going for the rest of this page. You want to predict what a house sells for, and the only thing you are allowed to look at is its size in square feet. So the function has one input, one output, and exactly one dial in the middle:

That dial is called a weight. Here it means dollars per square foot, and this is the “derived from data” part of the second ring in practice: nobody tells the model what the number should be. It has to arrive at a sensible one by being wrong first.

So start it at something useless — one dollar per square foot — and see what happens:

That last number is the error — later you will see it called loss. It is one number standing in for “how far off were we”, and collapsing the whole mess into one number is what makes the next part possible.

The error carries a direction as well as a size. The guess came in under the real price, which tells you the weight is too small, so the fix is to push it up. Had the model guessed a million, the same arithmetic would have come out negative and the weight would go down instead. That correction — prediction, comparison, adjustment — is the whole cycle, and the diagram below runs one turn of it: the house goes in, a bad answer comes out, reality disagrees, and the gap travels back to move the dial.

1,500 sqftthe inputsqft × weightthe modelPredictionwhat it saysActual pricewhat it sold forthe error goes back

Real training never jumps straight to the answer like that. It nudges the weight a little per house, over thousands of them, and the number drifts towards whatever dollars-per-square-foot fits the whole pile best. No single house gets to decide it.

Nothing here understands houses. The model has no idea what a bedroom is, or that people pay more near good schools. It found a number that makes its arithmetic line up with the prices you showed it. That is the whole trick, and it is worth remembering every time a model gets described as knowing something.

The three ingredients

You have now watched the whole thing happen once, so the rest of this section is only naming the parts. There are three, they are the three you were told you owed, and they do not change with scale: a model with one weight predicting house prices has them, and so does a model with a trillion weights writing paragraphs.

1. Parameters — the numbers the model owns

These are the dials training is allowed to turn. In the house example there is exactly one: the weight, dollars per square foot. Give the model more to look at — bedrooms, age, distance from a station — and each gets its own weight, plus a bias, a flat amount added at the end so the line does not have to start at zero. Weights and bias are both parameters — every weight is a parameter; not every parameter is a weight.

Everything else about the model is fixed by you. The parameters are the only part the data gets to touch.

2. Prediction — run the input through

Take an example, push it through the function with whatever the parameters currently are, and read the answer. Early in training this produces nonsense — $1,500 for a family home — and that is fine. You are not using the prediction, you are using how wrong it is.

3. Feedback — compare it to the truth

Put the prediction next to the real answer and turn the gap into a number. For one house that is the subtraction you already did. Across thousands of houses you need a single score for the whole batch, and squaring each gap before averaging them is the usual choice — it stops a guess that is too high cancelling out one that is too low, and it makes the badly wrong ones count for more.

That score has a name, mean squared error, and the general idea has one too: a loss function. Both are the same feedback step wearing a more formal label. Swap the family and only this ingredient changes — a reward instead of a label, or no feedback at all.

Notice what is missing from that list. There is no rule, no lookup table, no description of what makes a house expensive. Three ingredients, and none of them is knowledge.

Learning versus programming

That is the first ring against the second, and it is worth seeing the two written out side by side, because they end up at the same place: a function that turns square feet into a price. The only difference is who chose the number in the middle.

Write it yourself and you have committed to a rule. It is readable, it is testable, and it is exactly as good as your guess at $200:

price.tsTypeScript
function price(sqft: number): number {
  return sqft * 200; // you decided $200 per sqft
}

Now the same job with the number left blank and a pile of houses that already sold. Every ingredient from the last section is in these eight lines: weight is the parameter, guess is the prediction, error is the feedback.

train.tsTypeScript
let weight = 0; // nobody has decided anything yet

for (const [sqft, actualPrice] of soldHouses) {
  const guess = sqft * weight;
  const error = actualPrice - guess;

  weight += error * 0.0001; // nudge, do not leap
}

The 200 never appears. What you supplied instead was records of real sales and a way to measure a mistake, and the weight walked towards the right value on its own. That is the trade from earlier, paid in full: you give up writing the rule, and in exchange you get a rule you could not have written — one that would have taken a sit-down with a spreadsheet, and that you would have to redo by hand every time the market moved.

The 0.0001 is the nudge from the last section, given a size. It is the learning rate, and it is small on purpose: one oddly cheap house should move the weight, not yank it. Make it too large and the weight overshoots and thrashes; too small and training takes forever. It is the first knob you will find yourself arguing about.

ProgrammingMachine learning
Who picks the ruleYou do, in advanceThe examples do, during training
What happens with more dataNothing — the rule is what you typedThe rule gets sharper
The functionprice = sqft × 200price = sqft × weight, learned
When it is wrongYou read the code and fix itYou look at the data and the error, and often cannot point at a line

That last row is the real cost, and it is worth sitting with before you reach for a model. A hardcoded 200 that is wrong is a five-minute fix. A learned weight that is wrong sends you back to the examples you trained on.

Training and inference

The loop you just read is only half of a model’s life, and the two halves get confused constantly. While that loop runs you are training: you have the answers, and you are using them to move the weights. What happens afterwards is inference: the weights are frozen, a new listing arrives with no sale price attached, and the model returns a number nobody can check yet.

Same function both times. The difference is whether the answer is available, and whether anything is still changing.

Training
You have the real answers, and the parameters are still moving
Inference
No answer to compare against, and the parameters are held still
A model in production is always doing inference. It stopped learning the moment training ended. If the market shifts and the weight is stale, the model will keep confidently returning last year’s prices until somebody trains it again.

What “self-learning” really means

Which is what makes the phrase misleading. It suggests a model quietly getting cleverer overnight, improving because it exists. What somebody has actually built is the training loop wired up to run without a person pressing the button: new sales come in, feedback is collected automatically, retraining is scheduled, the updated weights are deployed.

Observea house appearsPredictit guesses a priceFeedbackit sold for thisTrainweights moverepeat

Only the fourth step is learning. The first three can run a million times a day in production and the model will be precisely as good at the end of the day as it was at the start; it is the step where numbers change that counts, and that step is training, not inference.

That tells you where these systems break, and it is almost never the maths. The feedback stops arriving. The retrain job fails silently for six weeks. Sale prices come back so late that the model is always learning from a market that has already moved on. A self-learning system with a broken feedback step is just a frozen model that nobody has noticed is frozen.

No loop, no learning. A model sitting in production answering requests is not improving, however much traffic it sees. It improves when someone closes the loop and the weights actually change.

Related concepts

TopicDescription
Artificial Intelligence (AI)What AI is at the first layer: human decisions turned into computer rules — before machine learning enters the picture.
Deep LearningMachine learning with stacked neurons and ReLU layers: how a deep network builds a price guess from house features in TypeScript.