AI Basics

Machine Learning Explained: Learning from Examples

A plain-language explanation of machine learning: how programs learn patterns from data instead of following hand-written rules, and where that approach goes wrong.

On this page
  1. Rules versus examples
  2. The basic ingredients
  3. How training works, in outline
  4. Main kinds of learning
  5. Training, testing and the problem of memorizing
  6. Where things go wrong
  7. Where you meet it every day
  8. What it is not
  9. A quick mental model

Rules versus examples

Suppose you want a program to sort email into “spam” and “not spam.” One approach is to write rules by hand: if the message contains certain words, or comes from an unknown sender, mark it as spam. This works for a while, then spammers change their wording, legitimate emails trip the rules, and the list of rules grows unmanageable.

Machine learning takes a different route. Instead of writing the rules, you give the program many examples of emails that people have already labeled, and a learning method finds patterns that separate the two groups. The “rules” end up being stored in numbers inside the model, not written by a person. That is the central idea: learning from examples rather than following explicit instructions.

The basic ingredients

Almost every machine learning project has the same parts.

  • Data. The examples the system learns from. The quality and variety of this material is the biggest influence on the outcome, a point explored further under training data.
  • Features. The pieces of information about each example that the model looks at, such as word counts for an email or the size and age of a house.
  • A model. A mathematical structure with adjustable settings, called parameters, that turns inputs into outputs.
  • A learning procedure. A method for adjusting the parameters so the model’s outputs get closer to the right answers.
  • A measure of error. A way to score how wrong the model currently is, so the procedure knows what to improve.

How training works, in outline

Start with a model whose settings are essentially arbitrary. Show it an example, compare its prediction with the correct answer, and measure the error. Then nudge the settings slightly in the direction that would have reduced the error. Repeat this over many examples, many times. Gradually the model’s predictions improve.

Notice what this does not involve: nobody tells the model what makes an email spammy. It discovers statistical regularities in the data. Sometimes those regularities match human intuition; sometimes they are surprising or even misleading.

Main kinds of learning

Supervised learning. The examples come with correct answers, called labels. Predicting a house price from its features, or recognizing handwritten digits, are typical cases. It is the most common type in everyday applications.

Unsupervised learning. There are no labels. The system looks for structure by itself, such as grouping similar customers or spotting unusual items. The results often need a person to interpret them.

Reinforcement learning. A system takes actions in an environment and receives rewards or penalties, gradually learning which actions lead to better outcomes. It has been used for game playing and for control problems.

Newer approaches, such as the self-supervised methods behind many language models, learn by predicting missing parts of the data itself, which lets them use large amounts of unlabeled material.

Training, testing and the problem of memorizing

A model can do very well on the examples it saw and badly on new ones. This is called overfitting, and it is like a student who memorizes past exam answers without understanding the subject.

To guard against it, practitioners hold back some data that the model never trains on and use it to test performance. If the model scores well on training data but poorly on the held-back data, it has probably memorized rather than learned. Honest evaluation depends on keeping that test material truly separate.

Where things go wrong

Learning from examples is powerful, but it inherits the limits of the examples.

  • Biased or unrepresentative data. If the data reflects past unfairness or leaves out certain groups, the model may reproduce or amplify those patterns. This is a main source of algorithmic bias.
  • Changing conditions. A model trained on yesterday’s patterns can drift out of date when the world changes.
  • Confusing correlation with cause. A model may use a feature that happens to go along with the answer without being its real cause. A classic hypothetical: if photos of one type of animal in the training set were mostly taken outdoors, the model might learn “grass” instead of the animal.
  • Opaque reasoning. Complex models can be hard to explain, which is why explainable AI is an active area.
  • Overconfidence. Models produce an answer even when the input is unlike anything they were trained on.

Where you meet it every day

Machine learning is used in recommendations for what to watch or read, in fraud detection by payment systems, in photo apps that group faces, in translation tools, in route estimates, in voice interfaces and in many forms of data analytics. Healthcare is another area where researchers are exploring it, covered under machine learning healthcare, always with the need for expert oversight.

What it is not

Machine learning is not the same as artificial intelligence as a whole; it is one approach within the field. It is also not magic. A model finds patterns that are present in its data, no more. It does not know why those patterns exist, and it has no common sense beyond what the data happens to encode.

A quick mental model

If you remember one thing, make it this: a traditional program is written to follow instructions, whereas a machine learning model is shaped by experience. That makes it flexible for problems that are too messy to describe with rules, such as recognizing a face or understanding casual speech. It also means that questions about the data, who collected it, what it leaves out and how it was checked, are as important as questions about the code.

The complete guide to ai basics

Unraveling the Mysteries of Artificial General Intelligence
Read the guide

Keep exploring

Guides from other topics

All topics →