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:
| Letter | Meaning | Example: reading handwritten digits |
|---|---|---|
| T | The task | Assign a label 0–9 to an 8×8 grayscale image |
| E | The experience | 1,257 images that already carry correct labels |
| P | The performance measure | Accuracy 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 examples | P — held-out accuracy |
|---|---|
| 10 | 0.4426 |
| 25 | 0.6148 |
| 50 | 0.8278 |
| 100 | 0.8889 |
| 200 | 0.9352 |
| 400 | 0.9444 |
| 800 | 0.9611 |
| 1,257 | 0.9722 |
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 to 40 points. The candidate space is every possible . The measure of badness is the mean squared error:
Now the search. Hold fixed and sweep :
| Candidate slope | MSE |
|---|---|
| 0.0000 | 1.3921 |
| 0.3000 | 0.6452 |
| 0.7173 | 0.2631 |
| 1.2000 | 0.7744 |
| 2.0000 | 3.8734 |
There is exactly one bottom to that curve, and it sits at . 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.
See it move
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:
| Model | Features carry signal | Features are pure noise |
|---|---|---|
| Logistic regression | 0.6677 | 0.5067 |
| RBF SVM | 0.6733 | 0.5117 |
| Random forest | 0.6357 | 0.5320 |
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.
| Term | Meaning | In the digits example |
|---|---|---|
| Feature (predictor, ) | An input column | The 64 pixel intensities |
| Target (label, ) | The thing being predicted | The digit, 0–9 |
| Sample (instance, row) | One example | One 8×8 image |
| Training set | Rows the model may learn from | 1,257 images |
| Test set | Rows held back for honest scoring | 540 images |
| Model | The fitted mapping from to | The learned coefficients |
| Parameters | Numbers the fitting procedure chooses | Regression weights |
| Hyperparameters | Numbers you choose before fitting | Regularisation strength |
| Loss / cost | The badness being minimised | Mean squared error |
| Overfitting | Fits the training set, fails on new data | Train 1.00, test 0.82 |
| Baseline | The dumbest defensible predictor | Always guess the commonest digit: 0.1019 |
| Generalisation | Performing well on unseen data | The 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.
flowchart LR H["Hyperparameters
you choose these"] --> F["Fitting procedure"] D["Training data
X and y"] --> F F --> P["Parameters
the procedure chooses these"] P --> M["Model"] M --> E["Evaluate on held-out data
THE only honest number"]
What ML is good for
The honest test is a checklist, and a problem should pass all four.
- A pattern exists. There is a genuine relationship between inputs and output. Predicting a fair coin flip fails here, permanently.
- 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.
- You have data. Examples of the mapping, enough of them, representative of what production will look like.
- 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.
| Problem | Verdict | Why |
|---|---|---|
| Flag fraudulent transactions | Good fit | Pattern exists, rules are unwritable, labels accumulate, 94% helps |
| Recommend the next article | Good fit | Behavioural pattern, huge data, wrong guesses are cheap |
| Compute a tax amount | Bad fit | The rule is written down in law. Just implement it. |
| Predict tomorrow’s lottery numbers | Bad fit | No pattern exists |
| Decide who gets a kidney transplant | Bad fit | 94% is not acceptable, and the ethics are not a modelling problem |
In code
The whole loop, in fifteen lines:
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.9722from 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.9722Three 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.
Your classifier gets 97% accuracy. What is the first thing you should check?
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.
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.
You train three different algorithms on the same data and all three score about 0.51. What is the most likely explanation?
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.
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.
Which of these is a hyperparameter rather than a parameter?
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.
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.
Your company needs software to compute sales tax for each order. Should you train a model?
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.
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.
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?
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.
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 coffeeWas this page helpful?
Let us know how we did
