Learn AI

Machine Learning Explained: How Computers Learn From Data

Learn AI — Foundations Beginner Part 3

Machine learning is one of the most important technologies behind modern AI. This beginner-friendly guide explains how computers learn patterns from data, the main types of machine learning and where it is used in the real world.

In the previous article, we looked at the basic journey behind many AI systems:

DATA → TRAINING → MODEL → INPUT → INFERENCE → OUTPUT

Now we can go one level deeper and look at one of the most important technologies that makes that process possible:

Machine learning.

Machine learning is one of the main reasons modern AI systems can recognise patterns, make predictions and improve at certain tasks without developers manually programming every possible rule.

If you want to understand modern artificial intelligence properly, machine learning is one of the foundational concepts you need to understand.

What is machine learning?

Machine learning is a field within artificial intelligence that allows computer systems to learn useful patterns from data and use those patterns to make predictions, classifications or decisions.

Instead of explicitly programming every rule, developers provide data and a training process that allows a model to discover relationships within that data.

This distinction is important.

Traditional programming often looks like:

RULES + DATA → OUTPUT

Machine learning can look more like:

DATA + EXAMPLES → TRAINING → MODEL → PREDICTION

The result is a system capable of handling problems where writing every possible rule manually would be extremely difficult.

Why do we need machine learning?

Some problems are simple enough to solve with ordinary programming.

For example:

If a customer spends more than R1,000, give them free delivery.

A developer can easily write that rule.

But imagine trying to write explicit rules for:

  • identifying whether an image contains a dog;
  • detecting fraudulent banking transactions;
  • predicting whether a machine is likely to fail;
  • recognising spoken words;
  • recommending a movie someone may enjoy; or
  • identifying unusual network behaviour.

These problems can involve thousands or millions of possible combinations of information.

Trying to manually describe every rule can become impractical.

Machine learning provides another approach.

Instead of writing every rule, we train a model to recognise useful patterns from examples.

A simple example: recognising spam email

Imagine you want to build a system that identifies spam email.

You could try creating rules such as:

  • if the subject contains certain words, flag the message;
  • if the sender is unknown, increase the risk;
  • if the message contains many links, increase the risk;
  • if certain phrases appear, increase the risk.

But spam changes constantly.

Attackers can vary wording, domains, formatting and behaviour.

A machine-learning model can instead be trained using many examples of messages labelled as:

SPAM

or

NOT SPAM

The model learns patterns across those examples.

When a new message arrives, the model can estimate which category it most closely resembles.

The three main types of machine learning

Machine learning is often introduced using three broad categories:

  • supervised learning;
  • unsupervised learning; and
  • reinforcement learning.

These categories describe different ways in which systems can learn from information or feedback.

1. Supervised learning

Supervised learning uses training data where the desired answer is already known.

In other words, the examples include labels.

Imagine a dataset containing information about thousands of email messages.

Each message is labelled:

Spam = Yes

or

Spam = No

The training process uses those examples to learn relationships between the input information and the correct labels.

Once trained, the model can attempt to classify new messages it has not seen before.

Examples of supervised learning

Supervised learning can be used for tasks such as:

  • fraud detection;
  • credit-risk prediction;
  • image classification;
  • sales forecasting;
  • customer churn prediction;
  • disease detection;
  • spam filtering; and
  • predictive maintenance.

Classification vs regression

Within supervised learning, two common types of problems are classification and regression.

Classification

Classification means predicting a category.

Examples:

  • fraud or not fraud;
  • spam or legitimate;
  • customer likely to leave or stay;
  • image contains a cat or dog.

Regression

Regression means predicting a numerical value.

Examples might include:

  • predicted sales next month;
  • estimated house price;
  • future energy consumption;
  • expected delivery time.

The difference is simple:

Classification predicts a category.

Regression predicts a number.

2. Unsupervised learning

Unsupervised learning works with data that does not necessarily contain predefined labels telling the model the correct answer.

Instead, the goal is often to discover structures, relationships or groups within the data.

Imagine you have information about 100,000 customers but you have not divided them into customer types.

An unsupervised approach might help identify groups of customers with similar behaviour.

Customer segmentation example

Suppose a retailer has customer information including:

  • purchase frequency;
  • average transaction value;
  • product categories;
  • time between purchases; and
  • response to promotions.

An unsupervised model might reveal clusters such as:

  • frequent high-value customers;
  • occasional bargain shoppers;
  • seasonal customers;
  • customers at risk of becoming inactive.

The system was not necessarily told those groups existed beforehand.

It identified patterns in the data.

What is clustering?

Clustering is one common unsupervised learning technique.

The objective is to group data points that are similar according to the information available.

Clustering can be useful for:

  • customer segmentation;
  • behaviour analysis;
  • grouping similar documents;
  • identifying unusual patterns; and
  • exploring datasets where the categories are not yet known.

3. Reinforcement learning

Reinforcement learning involves a system learning through interactions, actions and feedback.

The system receives a signal indicating whether an action was beneficial or harmful relative to the objective.

Over many interactions, the system can learn strategies that maximise long-term reward.

A simple analogy

Imagine learning to play a computer game.

You try an action.

If it helps you progress, that outcome provides positive feedback.

If it causes you to lose, that provides negative feedback.

Over time, you learn which actions tend to produce better results.

Reinforcement-learning systems use a more formal mathematical version of this general idea.

Where reinforcement learning can be used

Applications may include:

  • robotics;
  • game-playing systems;
  • resource optimisation;
  • control systems;
  • some recommendation problems; and
  • training or aligning certain AI systems.

What is a feature?

Another term you will frequently encounter in machine learning is feature.

A feature is a piece of information used by the model when making a prediction.

For example, imagine a model predicting the price of a house.

Possible features might include:

  • number of bedrooms;
  • property size;
  • location;
  • number of bathrooms;
  • age of the property; and
  • previous sale information.

The target output might be:

Estimated property value.

Features are therefore the input variables used to help the model perform the task.

How does a machine-learning model learn?

At a simplified level, the model makes predictions and the training process measures how wrong those predictions are relative to the training objective.

The internal parameters of the model are then adjusted to improve performance.

This process may occur many times across the training data.

Eventually, the aim is to produce a model that performs well not only on the examples it trained on, but also on new information.

This introduces another important concept:

generalisation.

What is generalisation?

A useful machine-learning model should perform well on new data it did not simply memorise during training.

This ability is called generalisation.

Imagine a student memorising the answers to one specific exam paper.

If the next exam contains identical questions, the student performs perfectly.

But if the questions change slightly and the student cannot solve them, the student has memorised the answers rather than learned the underlying concept.

Machine-learning models can face a similar problem.

What is overfitting?

Overfitting happens when a model learns the training data too closely and performs poorly on new data.

In effect, the model has become too specialised to the examples it saw during training.

Good model development therefore normally involves evaluating performance on data that was not used in exactly the same way during training.

Training data, validation data and test data

Machine-learning development commonly separates data into different groups for different purposes.

Training data

Used to train the model.

Validation data

Used during development to evaluate choices and tune the system.

Test data

Used to evaluate how well the final model performs on unseen examples.

The exact methodology varies, but the principle is important:

Do not judge a model only by how well it performs on information it already learned from.

Accuracy is not always enough

Imagine a fraud-detection dataset where only 1% of transactions are fraudulent.

A useless model could predict:

“Not Fraud”

for every transaction.

It would still be correct 99% of the time.

That sounds impressive until you realise it detected zero fraud.

This is why machine-learning evaluation often uses several metrics rather than looking only at overall accuracy.

The correct metrics depend on the business problem and the consequence of different types of mistakes.

Machine learning is about probability

Many machine-learning systems produce probabilities or scores rather than absolute certainty.

For example, a model might estimate:

Fraud probability: 92%

Another system then needs to decide what to do with that score.

For example:

  • below 30% → continue normally;
  • 30–70% → perform additional checks;
  • above 70% → request human review.

This illustrates an important business principle:

The model makes a prediction. The surrounding process determines the action.

Machine learning vs deep learning

Deep learning is a specialised area within machine learning based on neural networks with many layers.

Deep-learning approaches have been particularly successful in areas such as:

  • image recognition;
  • speech recognition;
  • natural language processing;
  • generative AI; and
  • complex pattern recognition.

A useful hierarchy is:

ARTIFICIAL INTELLIGENCE

↓

MACHINE LEARNING

↓

DEEP LEARNING

Deep learning is therefore part of machine learning, which is itself part of the broader field of artificial intelligence.

What are neural networks?

Neural networks are mathematical models inspired loosely by the idea of interconnected processing units.

They consist of layers of mathematical operations that transform information.

A simplified neural network might include:

INPUT LAYER → HIDDEN LAYERS → OUTPUT LAYER

During training, the network’s parameters are adjusted so that the model becomes better at its task.

Modern large language models are based on sophisticated deep-learning architectures.

We will explore those concepts in more detail later in the learning path.

Real-world machine-learning examples

Machine learning is already part of many systems people use every day.

Banking and finance

Machine learning can assist with fraud detection, credit assessment, anti-money-laundering monitoring and customer behaviour analysis.

Cybersecurity

Security products can use machine learning to identify unusual behaviour, malicious files, suspicious network activity or patterns associated with attacks.

Healthcare

Machine learning can assist with image analysis, risk prediction, research and other clinical-support applications.

Retail

Retailers use machine learning for recommendation systems, forecasting, customer segmentation, inventory planning and pricing analysis.

Manufacturing

Sensor information can be analysed to help predict equipment failures or identify unusual operating patterns.

Agriculture

Machine-learning techniques can support crop analysis, disease detection, yield forecasting and analysis of sensor or environmental data.

Streaming services

Recommendation systems analyse user behaviour to help determine which content might be relevant to each person.

A practical business example: predicting customer churn

Imagine a subscription company wants to identify customers who may cancel their service.

The company has historical information including:

  • length of subscription;
  • number of support calls;
  • product usage;
  • billing history;
  • complaints;
  • changes in usage patterns; and
  • whether previous customers eventually cancelled.

A supervised machine-learning model could be trained using this historical information.

The model might then produce a churn-risk score for current customers.

For example:

CustomerPredicted churn riskPotential action
Customer A12%No intervention
Customer B58%Review account
Customer C91%Retention team engagement

The machine-learning model does not need to make the business decision itself.

It provides a prediction that helps humans or another system prioritise attention.

The importance of bias

Machine-learning systems learn from data.

If the data reflects historical bias, missing groups, poor measurement or other problems, the model may reproduce or amplify those issues.

This becomes particularly important when AI is used in areas such as:

  • employment;
  • credit;
  • insurance;
  • healthcare;
  • law enforcement; or
  • other consequential decisions.

Responsible machine-learning development therefore requires more than simply achieving a good technical accuracy score.

Developers and organisations need to consider data quality, fairness, transparency, security and the impact of errors.

Machine learning does not eliminate human responsibility

A common mistake is to think that a machine-learning score removes the need for human judgement.

Imagine a system estimates that an employee has a high probability of leaving the company.

That does not mean the employee will definitely leave.

It is a model-generated estimate based on the information available.

The correct business response depends on:

  • the reliability of the model;
  • the consequences of being wrong;
  • ethical considerations;
  • privacy requirements;
  • business policy; and
  • appropriate human oversight.

Machine learning vs generative AI

Generative AI is strongly connected to machine learning, but the terms are not interchangeable.

Many generative AI models are built using advanced machine-learning and deep-learning techniques.

However, traditional machine-learning systems may perform tasks such as:

  • classification;
  • prediction;
  • forecasting; or
  • anomaly detection

without generating human-like text or images.

Generative AI focuses specifically on generating new content or outputs.

When should a business use machine learning?

Machine learning may be valuable when:

  • there is sufficient relevant data;
  • the problem involves patterns difficult to define with fixed rules;
  • predictions or classifications have meaningful business value;
  • performance can be measured; and
  • the cost and complexity are justified by the outcome.

It may not be appropriate when a simple business rule already solves the problem reliably.

For example:

“Send an alert when disk space falls below 10%.”

A normal rule is probably enough.

You do not need machine learning simply because machine learning exists.

A good machine-learning project starts with the business question

Instead of asking:

“Where can we use machine learning?”

ask:

“What important outcome are we currently struggling to predict, classify or understand?”

Examples might include:

  • Which customers are most likely to leave?
  • Which transactions are most likely to be fraudulent?
  • Which machines are most likely to fail?
  • What will demand look like next month?
  • Which security events deserve immediate attention?

Then evaluate whether machine learning is actually the right method for solving the problem.

A simplified machine-learning workflow

A practical machine-learning project might follow a process such as:

1. DEFINE THE PROBLEM

↓

2. COLLECT AND UNDERSTAND THE DATA

↓

3. PREPARE THE DATA

↓

4. TRAIN THE MODEL

↓

5. VALIDATE PERFORMANCE

↓

6. DEPLOY

↓

7. MONITOR

↓

8. IMPROVE

The monitoring stage is particularly important.

The world changes.

Customer behaviour changes.

Threat patterns change.

Markets change.

Data changes.

A model that performs well today may perform differently in the future.

What is model drift?

Model drift broadly refers to situations where the relationships a model depends on change over time and model performance may degrade.

For example, a fraud-detection model trained on historical attack patterns may become less effective as criminals change their behaviour.

This is why machine-learning systems often require ongoing monitoring rather than being treated as systems that can be trained once and forgotten forever.

Frequently asked questions

Is machine learning the same as AI?

No. Machine learning is a major field within artificial intelligence. AI is the broader concept.

Does all AI use machine learning?

No. Artificial intelligence is a broad field and can include approaches that are not based on modern machine learning.

What is supervised learning?

Supervised learning trains a model using examples where the desired output or label is already known.

What is unsupervised learning?

Unsupervised learning looks for patterns or structures in data without relying on predefined labels for every example.

What is reinforcement learning?

Reinforcement learning involves learning strategies through actions and feedback in order to improve performance toward an objective.

What is deep learning?

Deep learning is a specialised area of machine learning based on neural networks with multiple layers.

What is overfitting?

Overfitting happens when a model performs very well on its training data but fails to generalise well to new information.

Does machine learning need lots of data?

The amount of data required depends on the problem and technique. Data quality and relevance can be as important as volume.

Can machine-learning predictions be wrong?

Yes. Machine-learning models make predictions based on patterns and probabilities. Performance should be measured, limitations understood and appropriate oversight used.

Do businesses need data scientists to use machine learning?

Not always. Many modern products provide built-in machine-learning capabilities. However, custom machine-learning projects can require specialist skills in data, modelling, software engineering and governance.

Key takeaways

  • Machine learning is part of artificial intelligence.
  • Machine-learning systems learn useful patterns from data.
  • Supervised learning uses labelled examples.
  • Unsupervised learning discovers patterns without predefined labels.
  • Reinforcement learning uses actions and feedback.
  • Classification predicts categories; regression predicts numerical values.
  • A good model needs to generalise to new data.
  • Overfitting happens when a model learns its training data too closely.
  • Machine-learning predictions are not guarantees.
  • Data quality, bias, governance and monitoring matter.
  • The correct starting point is a business problem, not a machine-learning algorithm.

Continue the Learn AI journey

You now understand one of the most important building blocks behind modern artificial intelligence.

The next step is to examine the technology that brought AI directly into the hands of millions of ordinary users:

Generative AI.

In the next article, we will explore how generative systems differ from traditional predictive machine learning and why they can create text, images, code, audio and other new content.

Next: Generative AI Explained — How AI Creates Text, Images, Code and More →