Quick Answer
Machine learning is a technique that lets software learn from examples rather than following explicit rules written by a programmer. Instead of coding “if the email contains these words, it is spam”, you show the system thousands of spam and non-spam emails and let it learn the pattern itself. Modern AI, including ChatGPT, image recognition, and recommendation systems, runs on machine learning.
Dark industrial cylinder projecting rows of red data points into darkness: a machine learning model projects learned patterns outward from training data.
Machine learning extracts patterns from data and projects them forward: given enough examples, the model learns to see structure in new data it has never seen before.

The old way: explicit rules

Traditional software follows rules that programmers write by hand:

python
# A programmer had to think of every rule manually
def is_spam(email):
    if "click here to claim your prize" in email.lower():
        return True
    if "nigerian prince" in email.lower():
        return True
    # ... hundreds more rules
    return False

This breaks immediately when spammers change their wording. The programmer must constantly update rules.

The machine learning way: learn from examples

Instead of writing rules, you provide labelled examples and let the system find the pattern:

python
# You provide training data: emails with correct labels
training_data = [
    ("Click here to claim your prize!", "spam"),
    ("Hi, the meeting is at 3pm", "not_spam"),
    ("Get rich quick guaranteed!", "spam"),
    ("Invoice attached as discussed", "not_spam"),
    # ... thousands more examples
]

# The model learns what makes an email spam
model = train(training_data)

# Now it classifies new emails it has never seen
model.predict("Limited time offer! Act now!!")  # → "spam"

The key shift: the programmer no longer writes rules. The programmer curates data and the algorithm writes its own rules internally.

The three main types of machine learning

Supervised learning
Classification Regression Labelled data required. Examples: spam detection, image recognition, price prediction, credit scoring.
Unsupervised learning
Clustering Dimensionality reduction Anomaly detection No labels needed. Examples: customer segmentation, fraud detection, topic modelling.
Reinforcement learning
Policy learning Reward optimisation Agent learns by trial and error with rewards/penalties. Used in game AI, robotics, LLM alignment (RLHF).
Deep learning (subset)
Neural networks Transformers (LLMs) Diffusion models A technique within supervised/unsupervised ML using multi-layer neural networks. Powers most modern AI.

Supervised learning: learning with a teacher

The most common type. You provide labelled training data: inputs paired with correct outputs.

Examples:

  • Image classification: 10,000 photos each labelled “cat” or “dog”. The model learns visual features that distinguish them.
  • Price prediction: 50,000 property listings with sale prices. The model learns which features (size, location, age) predict price.
  • Sentiment analysis: 100,000 product reviews each labelled positive or negative. The model learns language patterns associated with sentiment.

Unsupervised learning: finding hidden structure

No labels required. The model finds patterns in unlabelled data.

Examples:

  • Customer segmentation: Group customers by purchasing behaviour without pre-defining what the groups are.
  • Anomaly detection: Learn what normal transaction patterns look like, then flag unusual transactions as potential fraud.
  • Topic modelling: Process 10,000 articles and automatically discover they cluster into topics like “finance”, “sports”, and “technology”.

Reinforcement learning: learning by doing

An agent takes actions, receives rewards or penalties, and learns which actions maximise reward over time.

Examples:

  • Game-playing AI (AlphaGo) learning to win by playing millions of games against itself
  • Language model alignment via RLHF (Reinforcement Learning from Human Feedback): humans rate responses and the model learns to produce responses humans prefer

The machine learning workflow

Step 1 Collect and label data Gather examples of inputs and correct outputs. This is often 80% of the work in a real ML project.
Step 2 Train the model An algorithm processes the data repeatedly, adjusting internal parameters to minimise prediction errors on the training set.
Step 3 Evaluate on held-out data Test the model on data it has never seen. This reveals whether it learned the true pattern or just memorised the training examples.
Step 4 Deploy and monitor Serve the model in production. Monitor for performance degradation as real-world data shifts away from the training distribution.

Common ML algorithms at a glance

AlgorithmBest forRequires
Linear regressionPredicting a continuous value (price, temperature)Small dataset, interpretability
Logistic regressionBinary classification (yes/no)Small dataset, interpretability
Decision treeRules-based classification, explainabilityStructured tabular data
Random forestHigh accuracy on tabular dataMore compute than single tree
Gradient boosting (XGBoost)Structured data competitions, fraud detectionCareful hyperparameter tuning
Neural network / deep learningImages, text, audio, complex patternsLarge datasets, significant compute
k-means clusteringCustomer segmentation, groupingUnlabelled data

When machine learning is not the right choice

When you have explicit rules that work: If a simple if/else logic covers 99% of cases reliably, ML adds complexity without benefit. Use rules first.

When you have too little data: Training a deep learning model on 100 labelled examples will not work. You need at minimum hundreds, usually thousands of examples.

When you need full explainability: If a regulatory requirement demands that every decision be explainable step by step (common in credit decisions, medical diagnosis), black-box ML models present legal and compliance challenges.

When the domain is rapidly changing: A model trained on last year’s data may degrade quickly if the real-world patterns shift. Some domains require continuous retraining to stay accurate.

What’s next

Further reading