🧠 Artificial intelligence

Machine learning explained simply: learning from examples

What machine learning is, how it differs from traditional programming and the main types of learning: supervised, unsupervised and reinforcement learning.

The term machine learning is often used as a synonym for artificial intelligence. In fact it is one part of it, and today the most important one: the set of techniques that let a computer learn to perform a task from examples, instead of following rules written by hand by a programmer. Let's see what that means in practice, without formulas.

Programming rules versus learning from examples

Imagine you have to write a program that recognises spam emails. With the traditional approach you would write explicit rules: "if the message contains the word winner and a link, it is spam". That works for a while, then spammers change their wording and the rules turn into a tangle that is impossible to maintain.

With machine learning the reasoning is turned upside down. You collect thousands of emails already labelled "spam" or "not spam", feed them to an algorithm and let it find out which characteristics separate the two categories. The result is a model: a mathematical function that, given a new email, returns the probability that it is spam.

The key difference is this:

  • in traditional programming you provide rules and data and get answers;
  • in machine learning you provide data and answers and get the rules, in the form of a model.

The basic ingredients

Every machine learning project revolves around a few elements.

  1. Data. These are the examples the model learns from. Each example is described by features: for a house they might be floor area, number of rooms, neighbourhood and year of construction.
  2. The label. This is the correct answer attached to the example, such as the house's sale price.
  3. The algorithm. This is the procedure that looks for the relationship between features and label. There are many families: linear regression, decision trees, neural networks and others.
  4. The loss function. It measures how far the model's predictions are from reality. Training consists of reducing this error step by step.

The three main types of learning

Supervised learning

This is the most common case. Every example has its label and the model learns to predict it. It splits into two main tasks: classification, when the answer is a category (spam or not spam, regular or suspicious transaction), and regression, when it is a number (price, temperature, delivery time).

Unsupervised learning

Here there are no labels. The model looks for hidden structure in the data. A typical example is clustering: an online shop can group customers by buying habits without knowing in advance which groups exist. It might discover that some people buy only during sales while others frequently make small purchases.

Reinforcement learning

The model, called an agent, acts in an environment and receives rewards or penalties depending on the results. Over time it learns a strategy that maximises rewards. This is the approach used to teach a system to play chess or to control a robotic arm in simulation.

Type Data required Practical example
Supervised Examples with the correct answer Estimating a property's price
Unsupervised Unlabelled examples Segmenting customers
Reinforcement Environment and reward system Optimising a game strategy

Training, validation and test

A common beginner's mistake is to evaluate the model on the same data used to train it. It is like preparing a student by handing over the exact exam questions in advance: they would score brilliantly without having understood anything.

That is why data is usually split into three parts:

  • training, to teach the model;
  • validation, to choose the best settings during development;
  • test, kept aside until the end, to measure how it will behave on data it has never seen.

Overfitting and underfitting

A model that learns the training data too well, noise and randomness included, suffers from overfitting: it is excellent on known examples and mediocre on new ones. Conversely, a model that is too simple suffers from underfitting and gets things wrong all the time, even on examples it knows. The goal is the balance point where the model generalises, meaning it captures the real pattern rather than accidental details.

Where you meet it every day

Machine learning already sits inside many common services, often without you noticing:

  • email spam filters;
  • film, music and product recommendations;
  • voice recognition in phone assistants;
  • travel time estimates in navigation apps;
  • banking systems that flag unusual card payments.

What machine learning does not do

A model learns only what is present in the data. If the data is scarce, unbalanced or old, the model will inherit those limits. It does not "reason" about the world in a human sense: it finds correlations. A correlation that is useful for prediction is not necessarily a cause, and confusing the two leads to bad decisions. That is why, alongside the technique, you always need people who know the domain and can interpret the results.

In short

  • Machine learning lets computers learn tasks from examples rather than from hand-written rules.
  • The three main types are supervised, unsupervised and reinforcement learning.
  • A model must be evaluated on data it has never seen, to avoid overfitting.
  • The quality of the result depends on the quality of the data and on human interpretation.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also