Technology & Computing · AI & machine learning

How machine learning works

A machine-learning system isn't given the rules. It's shown examples and adjusts itself until its guesses improve. See how training works, why a model can ace its lessons and fail in the world, and how it's tested.

4 short lessons · about 16 minutes · 9 sources · updated November 2026

What you will learn

  • Name the features, label and learned numbers in a simple model
  • Describe how training lowers a model's loss step by step
  • Explain what overfitting is and why it fails on new data
  • Explain why a model must be tested on data kept apart from training

Lesson 1 of 4 · 4 min

How a model learns a car's mileage from examples

Before you readYou want software that estimates a car's miles per gallon. With machine learning, what do you mainly give it?

Correct.Not quite. The answer is Cars whose weight and real mileage are known.

You give it examples with answers, and it works out the relationship itself. This lesson follows that process for seven cars.

The term machine learning was coined in 1959 by Arthur Samuel, an IBM researcher working on checkers. It means software that learns from data and then handles new data, so it can do a task without being explicitly programmed.

Say you want an app that predicts rain. One route is to write physics equations for the whole atmosphere, which is very hard. The machine-learning route is to give a model huge amounts of weather data until it learns how weather patterns relate to rainfall.

The most common kind is supervised learning. Each training example has features and a label. Features are the values the model uses to predict. The label is the right answer it's trying to predict.

Google's machine learning course uses cars. The feature is a car's heaviness, and the label is its real miles per gallon. Heavier cars generally get fewer miles per gallon, so the course fits a straight line through seven cars.

That line is the model. It predicts mileage as 34 minus 4.6 for every thousand pounds. The negative 4.6 is a learned number called a weight, and the 34 is another called the bias. A 4,000-pound car gets a predicted 15.6 miles per gallon.

Check yourselfIn a model that predicts a car's miles per gallon from its heaviness, what is the label?

Correct.Not quite. The answer is The car's real miles per gallon.

The label is the answer the model predicts. Heaviness is the feature it predicts from, and negative 4.6 is a weight it learns.

Where do 34 and 4.6 come from? The model finds them by shrinking its loss, a number for how wrong its predictions are. For a 2,370-pound car, the line predicts 23.1 miles per gallon. The car really gets 24. Squaring the gap of 0.9 gives a loss of 0.81 for that car.

Training starts with both numbers at zero. With both at zero, the model predicts zero miles per gallon for every car, and its average squared loss on the seven cars is 303.71.

Then a method called gradient descent repeats four steps. Work out the loss with the current numbers. Work out which direction to nudge them to lower it. Move them a small amount that way. Repeat until the loss stops falling, at which point the model has converged.

Try to recallHow does gradient descent find good numbers for a machine-learning model?

It starts with the model's numbers near zero and measures the loss, how wrong the predictions are. It works out which direction to nudge the numbers to lower the loss, moves them a small step and repeats. It stops when the loss won't fall any further.

A supervised model predicts a label from features using numbers it learns. Training finds those numbers by measuring the loss and nudging the numbers downhill until it stops falling.

Lessons in this topic

  1. How a model learns a car's mileage from examples

    Follow a simple model from blank numbers to useful predictions, and see what it means to shrink the error.

    Essentials · 4 min

  2. When a model memorizes instead of learning

    See why a model can ace its training data and fail on new data, and how keeping some data unseen catches it.

    Essentials · 4 min

  3. Learning with no answers and learning by reward

    See how a model can find groups in data nobody labeled, and how a game-playing system learns from rewards alone.

    Deeper · 4 min

  4. Why a model is only as good as its data

    See how true patterns in data can still mislead a model, and how differences between training data and real use break it.

    Deeper · 4 min

Three quick stories from this topic

Where the name came from

The term machine learning was coined in 1959 by an IBM researcher working on checkers

Arthur Samuel's checkers program remembered positions it had already seen. He also had it play thousands of games against itself as another way to learn, an idea game-playing systems still use.

No explicit program

Machine learning means software that learns from data and handles data it hasn't seen, so it can do tasks without being explicitly programmed.

Still the same loop

A modern model still learns by adjusting its numbers to shrink a measure of how wrong its predictions are.

The self-taught backgammon player

A backgammon program that played 1.5 million games against itself changed how experts open

Gerald Tesauro's TD-Gammon trained against itself in 1993 and reached a level just below the top human players. Expert players accepted and adopted its unconventional assessment of some opening strategies.

Rewards, not answers

Reinforcement learning gets a reward instead of correct answers. The learner finds which actions pay by trying them.

Rewards can misfire

A simulated bicycle rewarded for heading toward a goal, and never penalized for heading away, learned to ride in circles.

X-rays that name their hospital

Pneumonia-spotting AI could tell which hospital an X-ray came from over 99.9% of the time

In a 2018 study of 158,323 chest X-rays, pneumonia showed up in 34.2% of one hospital's images and about 1% of the others'. Knowing the hospital was a shortcut, and the models did worse at outside hospitals.

A clue that doesn't travel

The hospital gave the models a clue in training. At a new hospital the clue didn't hold, so accuracy fell.

Data decides

A model uses any pattern that works in its data, including where the data came from.

Sources

  • How a language model produces an answer

    See how tokens, context and learned patterns produce fluent answers, and why those answers still need checking.

    4 lessons · 17 min

  • How text becomes numbers

    Before a language model reads anything, the text is cut into tokens and each token becomes a point in a space where distance stands for meaning.

    4 lessons · 24 min

  • What artificial intelligence is

    AI is one label for many machines, from spam filters to chatbots. See what they share, how learned systems differ from hand-written rules, and how to test a claim about what AI can do.

    4 lessons · 16 min

  • How encryption works

    Encryption scrambles a message so only someone with the right key can read it. See how a shared key works, how strangers agree on one in public, and what end-to-end encryption in a chat app promises.

    4 lessons · 16 min

  • Passwords, passkeys and account security

    See how passwords get stolen, how a passkey signs you in with nothing to steal, and why account recovery needs as much care as sign-in.

    4 lessons · 17 min

  • Searching a million items

    See why a sorted list of a million items takes about 20 checks to search, when sorting first is worth the effort, and how a hash table skips the search altogether.

    4 lessons · 17 min

All technology & computing topics · Take the quiz