TExcelTAD
Home › Machine Learning › What is Machine Learning?

What is Machine Learning?

You have now trained regressions, trees, clustering and nearest-neighbour models. Let's step back and look at the bigger picture: what exactly makes something "machine learning", and how do the different kinds of ML relate to each other?

Rules vs learning

In traditional programming, a person writes the rules:

text
data + rules  ->  program  ->  answers

In machine learning, the computer derives the rules from examples:

text
data + answers  ->  learning algorithm  ->  rules (the model)

Take a simple spam filter. A hand-written version might be:

python · try it yourself
def is_spam_by_rules(subject):
    banned = ["free money", "winner", "act now"]
    return any(word in subject.lower() for word in banned)

for s in ["You are a WINNER", "Meeting moved to 3pm", "Claim your prize today"]:
    print(f"{s!r:28} -> spam? {is_spam_by_rules(s)}")
'You are a WINNER'           -> spam? True
'Meeting moved to 3pm'       -> spam? False
'Claim your prize today'     -> spam? False

It misses "Claim your prize today" because nobody wrote a rule for it. A learning system instead looks at thousands of labelled emails and figures out which words matter — and it can be retrained when spammers change tactics. You will build one in the Working with Text lesson.

The three main types of learning

Type Training data Goal Examples
Supervised inputs with correct answers (labels) predict the label for new inputs price prediction, spam detection, diagnosis
Unsupervised inputs without labels discover structure customer segments, anomaly detection, compression
Reinforcement an environment that gives rewards learn actions that maximise reward game-playing agents, robot control

Supervised learning splits further into regression (the label is a number) and classification (the label is a category).

python · try it yourself
from sklearn.datasets import load_iris, load_diabetes
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.cluster import AgglomerativeClustering

# supervised regression: target is a number (disease progression score)
Xd, yd = load_diabetes(return_X_y=True)
reg = LinearRegression().fit(Xd, yd)
print("regression     -> first prediction:", reg.predict(Xd[:1]).round(1))

# supervised classification: target is a class (iris species)
Xi, yi = load_iris(return_X_y=True)
clf = DecisionTreeClassifier(max_depth=2, random_state=0).fit(Xi, yi)
print("classification -> first prediction:", clf.predict(Xi[:1]))

# unsupervised clustering: no target at all
groups = AgglomerativeClustering(n_clusters=3).fit_predict(Xi)
print("clustering     -> first five groups:", groups[:5])
regression     -> first prediction: [206.1]
classification -> first prediction: [0]
clustering     -> first five groups: [1 1 1 1 1]

Notice the fit calls: supervised models receive X and y; the clustering model receives only X.

Other flavours you'll hear about

  • Semi-supervised learning: a few labelled examples plus many unlabelled ones.
  • Self-supervised learning: the data provides its own labels (predict the next word of a sentence). Large language models are trained this way.
  • Deep learning: not a separate type, but a family of models (neural networks with many layers) used for all of the above.

Reinforcement learning in a nutshell

Reinforcement learning (RL) is different from the rest of this course: there is no fixed data set. An agent takes actions in an environment and receives rewards. Over many trials it learns which actions pay off. Here is a tiny "multi-armed bandit": three slot machines with unknown win rates, and an agent that mostly plays the best machine so far but sometimes explores:

python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
true_win_rate = [0.2, 0.5, 0.7]          # unknown to the agent
wins = np.zeros(3)
plays = np.zeros(3)

for step in range(500):
    if rng.random() < 0.1 or plays.min() == 0:      # explore 10 % of the time
        arm = rng.integers(3)
    else:                                           # exploit the best estimate
        arm = np.argmax(wins / plays)
    reward = rng.random() < true_win_rate[arm]
    plays[arm] += 1
    wins[arm] += reward

print("plays per machine:", plays.astype(int))
print("estimated win rates:", (wins / plays).round(2))
plays per machine: [ 14 455  31]
estimated win rates: [0.14 0.49 0.65]

The agent discovered that machine 2 pays best and spent most of its plays there. Real RL (robots, game AIs) uses the same explore/exploit idea with far bigger state spaces.

Key vocabulary

Term Meaning
Feature an input variable (a column of X)
Label / target the answer to predict (y)
Sample / instance one row
Model the learned function from features to predictions
Training fitting the model's parameters to data
Inference using a trained model to make predictions
Generalisation performing well on new, unseen data

Note: Machine learning is a subfield of artificial intelligence (AI). Not all AI is ML (classic chess engines use search, not learning), and not all ML is deep learning.

Test yourself

Predicting tomorrow's temperature in degrees from today's weather data is…

  1. Unsupervised clustering
  2. Supervised regression
  3. Supervised classification
  4. Reinforcement learning

Grouping customers by shopping behaviour when no groups are known in advance is…

  1. Supervised learning
  2. Unsupervised learning
  3. Reinforcement learning
  4. Regression

What does a reinforcement-learning agent learn from?

  1. A table of labelled examples
  2. Rewards received after its actions
  3. Only unlabelled images
  4. Hand-written rules