Foundations · Lesson 2 of 3

How machine learning works

5 min readFacts checked 2026-11-266 cited sources

Most modern AI is built with machine learning. Instead of writing every rule by hand, people show a computer many examples and let it adjust itself until its answers improve. Here is how that loop works.

The machine learning training loopTraining examples with known answers go into the model. The model makes a guess. The guess is compared with the right answer, and the size of the error is the loss. Gradient descent nudges the model's weights to reduce the loss, and the loop repeats many times. Finally the model is checked on data it has never seen.Examplesinputs with known answersModel makes a guessusing its current weightsMeasure the errorguess vs. answer = the lossAdjust the weightsa small step (gradient descent)repeatTest on unseen datadoes it generalize, or did itjust memorize? (overfitting)
The training loop. Real systems run it many times over huge datasets, but every step is the one shown here.

Rules vs. examples

In traditional programming, a person writes the rules: if the email contains these words, mark it as spam. In machine learning (ML), a person supplies examples, such as thousands of emails already labeled spam or not spam, and the system learns its own rules from them.

The idea is old. In 1959 Arthur Samuel of IBM published a study of programs that learned to play checkers, and reported that a computer could be programmed to learn to play a better game than the person who wrote the program [1]. Samuel is widely credited with popularizing the term "machine learning".

The four ingredients

  • Data: examples. In the most common setup each example has inputs (say, a home's size and location) and a known answer (its sale price).
  • A model: a mathematical function with adjustable numbers called weights (and a bias). Training means finding good values for them [2].
  • A loss: a single number that measures how wrong the model's guesses are across the examples. Lower is better [2].
  • An optimizer: the method that changes the weights to lower the loss. The workhorse is gradient descent.

Gradient descent, without the math

Imagine standing on a foggy hillside and trying to reach the valley floor. You can't see the bottom, but you can feel which way the ground slopes under your feet, so you take a small step downhill, feel again, and repeat. Gradient descent does the same with the loss: it works out which direction of change to the weights would reduce the loss, takes a small step that way, and repeats, iteratively finding the weights that produce the lowest loss [2].

The size of each step is the learning rate. Too small and training crawls; too large and the loss can jump around wildly instead of settling [3]. Choosing it well is part of the craft.

Three main ways to learn (and a fourth)

Google's introductory ML course groups systems by how they learn [4]:

  • Supervised learning: learning from examples that include the correct answers, like a student practicing with old exams that come with an answer key. Predicting a number (rainfall, a price) is regression; predicting a category (spam or not) is classification [4].
  • Unsupervised learning: finding structure in data with no answers attached, such as grouping similar customers.
  • Reinforcement learning: learning by trial and error, earning rewards or penalties for actions in an environment.
  • Generative AI: models that create new content, such as text or images, from what they learned [4]. The next lesson looks at one kind: large language models.

A worked example: teaching a spam filter

Here is the whole loop in one everyday case. Start with a large pile of emails that people have already marked as spam or not spam. Each email becomes a set of inputs the model can work with: which words appear, who sent it, how many links it contains. The model starts with weights that are close to random, so its first guesses are no better than a coin toss.

For each email, the model guesses a probability that it is spam. The loss measures how far those guesses are from the labels people supplied. Gradient descent then nudges each weight a little in the direction that would have made the guesses better: perhaps the word "winner" gets a bit more weight toward spam, and your colleague's address a bit more toward not spam. After many passes through the data, the weights settle into a pattern that sorts most emails correctly.

Notice what nobody did: no one wrote a rule saying "winner means spam". The rule emerged from the examples. Notice also what that implies. If the training emails were all in English, or all from 2015, the filter will struggle with what it never saw.

The trap: overfitting

A model can get very good at the examples it trained on and still fail on new data. That is overfitting: performing well on training data but poorly on new, unseen data [5]. It is the ML version of memorizing the answer key instead of learning the subject. Common causes include training data that doesn't represent the real world and models that are more complex than the problem needs [5].

The standard defense is to hold some data back. Engineers train on one set and watch the loss on a separate validation set. If the training loss keeps falling while the validation loss starts rising, the model has begun to overfit [6].

Why this matters to you

Every ML model is a summary of its training data. If the examples were narrow, skewed or out of date, the model will be too, and it won't tell you. That is why the useful questions about any AI system are about its data and its testing, not just its accuracy score.

Try it

Be the model. Here are three homes: 1,000 sq ft sold for $200k, 1,500 sq ft for $300k, 2,000 sq ft for $400k (made-up numbers). Guess a rule, then predict the price of a 1,750 sq ft home. Now add a fourth home: 1,600 sq ft for $520k. Does your rule still fit? What extra input (location? condition?) might explain it? You just did training, testing and feature design.

Key takeaways

  • Machine learning learns rules from examples instead of having people write them.
  • Training adjusts a model's weights to reduce a loss, usually with gradient descent.
  • The learning rate sets the step size; too big and training becomes unstable.
  • Supervised, unsupervised and reinforcement learning differ in what feedback the model gets.
  • Overfitting means memorizing the training data; validation data exposes it.

Sources

  1. A. L. Samuel, “Some Studies in Machine Learning Using the Game of Checkers,” IBM Journal of Research and Development 3(3), 1959, pp. 210–229
  2. Google Machine Learning Crash Course, “Linear regression: Gradient descent”
  3. Google Machine Learning Crash Course, “Linear regression: Gradient descent exercise”
  4. Google for Developers, “Introduction to Machine Learning: What is ML?”
  5. Google Machine Learning Crash Course, “Overfitting”
  6. Google Machine Learning Crash Course, “Overfitting: Interpreting loss curves”

How this lesson was made: drafted with AI (Claude, by Anthropic, working as Lumiversed's website engineer), with every factual claim checked against the sources above on 2026-11-26. Reviewed by V (founder), Lumiversed's human engineer, on 2026-11-26. Spotted an error? Tell us.