Skip to content

What is Machine Learning?

What you’ll learn

  • Tom Mitchell’s T / E / P definition, and it plotted as a real curve: 0.4426 → 0.9722
  • what “the model learns” means concretely — a number chosen to minimise an error
  • why a baseline is the first thing you compute, not the last
  • the vocabulary you will use for the rest of this module
  • a measured demonstration that no algorithm can invent a signal that is not there

Intuition

Here is the whole idea, and it is genuinely this small.

You want a program that maps inputs to outputs — an image to a digit, an email to spam-or-not, a house to a price. You cannot write the rules, because you do not know them. What you do have is examples of the mapping: thousands of images with their correct digits.

So instead of writing the program, you write a program that searches for the program. You give it a family of candidate mappings, a way to score how badly a candidate does on your examples, and a procedure for finding a candidate that scores well.

That is machine learning. Three ingredients: a space of candidates, a measure of badness, and a search.

The definition

Tom Mitchell’s 1997 formulation is still the sharpest one available:

A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.

Its virtue is that all three letters are things you can point at:

LetterMeaningExample: reading handwritten digits
TThe taskAssign a label 0–9 to an 8×8 grayscale image
EThe experience1,257 images that already carry correct labels
PThe performance measureAccuracy on 540 images the model has never seen

The definition is also testable, which is unusual for a definition. Fix T, fix P, vary E, and see whether P actually improves. Here it is, run for real:

E — labelled examplesP — held-out accuracy
100.4426
250.6148
500.8278
1000.8889
2000.9352
4000.9444
8000.9611
1,2570.9722
figureMitchell's definition, measuredmatplotlib
A rising curve of held-out accuracy against the number of training examples on a logarithmic axis, climbing from 0.44 at 10 examples to 0.97 at 1257, far above a dashed baseline at 0.10.A rising curve of held-out accuracy against the number of training examples on a logarithmic axis, climbing from 0.44 at 10 examples to 0.97 at 1257, far above a dashed baseline at 0.10.
The task and the performance measure never change. Only the number of examples does. Accuracy climbs from 0.4426 to 0.9722 while the always-guess-the-most-common-digit baseline sits at 0.1019. This curve is what the word 'learn' means operationally.

Two details worth pausing on.

The baseline is 0.1019. Ten digits, roughly balanced, so guessing the most common one gets you about a tenth. Every accuracy number is only meaningful relative to that. A model at 0.85 on a problem whose baseline is 0.84 has learned essentially nothing.

The gains shrink. Going from 10 to 100 examples bought 0.4463. Going from 800 to 1,257 bought 0.0111. Almost every learning curve looks like this, and it is why “just get more data” stops being good advice at some point.

What “learning” actually is

Strip away the vocabulary and a model is a set of numbers, chosen to make an error as small as possible.

Take the simplest case: fit a straight line y=wx+by = wx + b to 40 points. The candidate space is every possible (w,b)(w, b). The measure of badness is the mean squared error:

MSE(w,b)=1ni=1n(yi(wxi+b))2\mathrm{MSE}(w, b) = \frac{1}{n}\sum_{i=1}^{n} \big(y_i - (w x_i + b)\big)^2

Now the search. Hold bb fixed and sweep ww:

Candidate slope wwMSE
0.00001.3921
0.30000.6452
0.71730.2631
1.20000.7744
2.00003.8734

There is exactly one bottom to that curve, and it sits at w=0.7173w = 0.7173. That number is the trained model. Everything else in this module — gradient descent, regularisation, boosting — is a more sophisticated way of finding the bottom of a more complicated curve.

figureFitting is finding the bottom of a curvematplotlib
Left panel: forty scattered points with three candidate straight lines, the best one highlighted. Right panel: a U-shaped curve of mean squared error against candidate slope, with its minimum marked.Left panel: forty scattered points with three candidate straight lines, the best one highlighted. Right panel: a U-shaped curve of mean squared error against candidate slope, with its minimum marked.
Left: three candidate lines through the same points; only one minimises the vertical distances. Right: the error as a function of the slope. The minimum sits at slope 0.7173 with MSE 0.2631 — that pair of numbers is the entire trained model.

See it move

sketch Searching for the bottom p5.js
A candidate line rotates through every slope while a marker traces the resulting error onto the curve below. Where the marker reaches the bottom of the curve is where the fitted line sits on the points.

There is nothing else in the box. A model family gives you the shape of the candidate line, a loss gives you the curve on the right, and training is the search for its lowest point.

ML is not magic

The most useful thing a beginner can internalise is what machine learning cannot do.

A model can only find relationships that are present in the features you give it. If the columns carry no information about the target, no algorithm recovers it. Not a bigger model, not more epochs, not a fashionable architecture.

Here is that claim, measured. Three thousand rows, a coin-flip target, and two feature sets: one where a column genuinely correlates with the label, one that is pure Gaussian noise. Same three algorithms on both:

ModelFeatures carry signalFeatures are pure noise
Logistic regression0.66770.5067
RBF SVM0.67330.5117
Random forest0.63570.5320
figureThree algorithms, one dataset with nothing in itmatplotlib
A grouped bar chart. Green bars for informative features sit near 0.65 to 0.67; red bars for noise features cluster just above the 0.5 dashed coin-flip line.A grouped bar chart. Green bars for informative features sit near 0.65 to 0.67; red bars for noise features cluster just above the 0.5 dashed coin-flip line.
With an informative column, all three land around 0.64 to 0.67. With pure noise, all three land within 0.032 of a coin flip. The random forest's 0.5320 is the largest deviation — and it is cross-validation noise, not a discovery.

Note also the left-hand column: even with signal, the ceiling is 0.6733. The signal was deliberately weak, and no algorithm exceeded what the data allowed. The features set the ceiling. The algorithm decides how close you get to it. That ordering does not change anywhere in this module.

Core vocabulary

Every one of these terms appears in every later phase. Learn them once, here.

TermMeaningIn the digits example
Feature (predictor, XX)An input columnThe 64 pixel intensities
Target (label, yy)The thing being predictedThe digit, 0–9
Sample (instance, row)One exampleOne 8×8 image
Training setRows the model may learn from1,257 images
Test setRows held back for honest scoring540 images
ModelThe fitted mapping from XX to yyThe learned coefficients
ParametersNumbers the fitting procedure choosesRegression weights
HyperparametersNumbers you choose before fittingRegularisation strength
Loss / costThe badness being minimisedMean squared error
OverfittingFits the training set, fails on new dataTrain 1.00, test 0.82
BaselineThe dumbest defensible predictorAlways guess the commonest digit: 0.1019
GeneralisationPerforming well on unseen dataThe only thing that matters

Two of these get confused constantly, so state the difference explicitly. Parameters are found by fitting — you never type them. Hyperparameters are set before fitting and control how the fitting happens. In LogisticRegression(C=0.1)LogisticRegression(C=0.1), CC is a hyperparameter; the coefficients it produces are parameters.

diagram Diagram mermaid

What ML is good for

The honest test is a checklist, and a problem should pass all four.

  1. A pattern exists. There is a genuine relationship between inputs and output. Predicting a fair coin flip fails here, permanently.
  2. You cannot write the rules. If you can specify the mapping precisely, write the code — it will be faster, cheaper, exactly correct and debuggable. Nobody should train a model to compute VAT.
  3. You have data. Examples of the mapping, enough of them, representative of what production will look like.
  4. Approximately right is useful. A model that is right 94% of the time has to be worth something. If only 100% will do, machine learning is the wrong tool.
ProblemVerdictWhy
Flag fraudulent transactionsGood fitPattern exists, rules are unwritable, labels accumulate, 94% helps
Recommend the next articleGood fitBehavioural pattern, huge data, wrong guesses are cheap
Compute a tax amountBad fitThe rule is written down in law. Just implement it.
Predict tomorrow’s lottery numbersBad fitNo pattern exists
Decide who gets a kidney transplantBad fit94% is not acceptable, and the ethics are not a modelling problem

In code

The whole loop, in fifteen lines:

first_model.py
from collections import Counter
 
from sklearn.datasets import load_digits
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
 
X, y = load_digits(return_X_y=True)                  # E — the experience
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, random_state=0, stratify=y)
 
# The baseline FIRST. Always. Everything else is measured against it.
baseline = Counter(y_test).most_common(1)[0][1] / len(y_test)
print("baseline     ", round(baseline, 4))           # 0.1019
 
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=5000))
model.fit(X_train, y_train)                          # the search
 
print("train size   ", len(X_train))                 # 1257
print("test accuracy", round(model.score(X_test, y_test), 4))   # 0.9722
first_model.py
from collections import Counter
 
from sklearn.datasets import load_digits
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
 
X, y = load_digits(return_X_y=True)                  # E — the experience
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, random_state=0, stratify=y)
 
# The baseline FIRST. Always. Everything else is measured against it.
baseline = Counter(y_test).most_common(1)[0][1] / len(y_test)
print("baseline     ", round(baseline, 4))           # 0.1019
 
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=5000))
model.fit(X_train, y_train)                          # the search
 
print("train size   ", len(X_train))                 # 1257
print("test accuracy", round(model.score(X_test, y_test), 4))   # 0.9722

Three habits worth forming from the very first model:

Split before you look. train_test_splittrain_test_split comes before any inspection, cleaning or plotting. Every decision you make after seeing the test set leaks information into your final number.

Compute the baseline first. It costs one line and it is the only thing that makes your accuracy interpretable.

Use a PipelinePipeline. Scaling belongs inside it. The moment preprocessing happens outside, it gets fitted on the test data too, and your score becomes fiction. Phase 2 covers why.

Pitfalls

Reporting accuracy with no baseline. 0.97 on digits is excellent (baseline 0.10). 0.97 on a problem with 97% negatives is worthless. The number alone tells you nothing.

Judging on the training set. Any sufficiently flexible model can memorise. Train accuracy is a measure of memory, not of learning.

Believing a bigger model fixes bad features. Measured above: the noise columns produced 0.5067, 0.5117 and 0.5320 across three very different algorithms. Feature quality is a ceiling.

Skipping the “can I just write the rule?” question. A great deal of production machine learning would have been three ifif statements.

Treating “the model is 94% accurate” as a property of the model. It is a property of the model on that test set. Change the population and the number changes.

Recap

  • T / E / P: fix the task and the measure, add experience, and watch performance improve — measured here from 0.4426 to 0.9722 against a 0.1019 baseline.
  • A model is a set of numbers minimising a loss. For a straight line that was slope 0.7173 with MSE 0.2631.
  • The gains from more data shrink: +0.4463 from the first 90 examples, +0.0111 from the last 457.
  • No algorithm can extract a signal the features do not carry — three of them landed within 0.032 of a coin flip on pure noise.
  • Parameters are learned; hyperparameters are chosen.
  • Split first, baseline first, pipeline always.
quizCheck yourself
  1. Your classifier gets 97% accuracy. What is the first thing you should check?

    Show answer

    B — What the baseline is — always guessing the majority class may already give 96% — Accuracy is meaningless in isolation. On digits the majority-class baseline is 0.1019, so 0.9722 is a real achievement. On a dataset with 96% negatives, 97% is barely better than doing nothing.

  2. You train three different algorithms on the same data and all three score about 0.51. What is the most likely explanation?

    Show answer

    B — The features carry no information about the target — When very different algorithms agree on a near-chance score, the limitation is the data, not the model. Measured on the page: logistic 0.5067, RBF SVM 0.5117 and random forest 0.5320 on pure noise. Fix the features, not the algorithm.

  3. Which of these is a hyperparameter rather than a parameter?

    Show answer

    B — The regularisation strength C in LogisticRegression(C=0.1) — Parameters are chosen by the fitting procedure — coefficients, intercepts, weights. Hyperparameters are chosen by you before fitting and control how the fitting behaves. C is set in the constructor, so it is a hyperparameter.

  4. Your company needs software to compute sales tax for each order. Should you train a model?

    Show answer

    B — No — the rule is written down in law, so implement it exactly — Criterion 2 of the checklist: if you can write the rule, write it. Code is faster, exactly correct, debuggable and free. A model would be approximately right, which for tax is a defect and not a feature.

  5. Going from 10 to 100 training examples raised accuracy by 0.4463. Going from 800 to 1,257 raised it by 0.0111. What does that pattern indicate?

    Show answer

    B — Diminishing returns — most learning curves flatten, so more data eventually stops being the cheapest improvement — Learning curves are concave almost universally. Once you are on the flat part, feature work, better labels or a different model class usually buy more than another batch of rows — and diagnosing that is exactly what a learning curve is for.

🧪 Try It Yourself

Exercise 1 – Baseline before model

Exercise 2 – Watch P improve with E

Exercise 3 – Find the bottom of the error curve

Exercise 4 – Prove that noise stays noise

Exercise 5 – Train accuracy is not learning

Exercise 6 – Price the next batch of data

Next

ML vs Traditional Programming — thirty hand-written rules against one fitted model on the same spam corpus, and the measurement that shows which of the two responds to more data.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did