Skip to chapter content
navan✳THE BUILD LABMACHINE LEARNING / GUIDE
0/28 read
CHAPTER 04 / 28 · FIRST PRINCIPLES

Numbers and uncertainty.

Understand averages, spread, proportions, and why a sample does not tell the whole story.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

Machine learning uses numbers to summarise data and compare predictions. The mean, or arithmetic average, is the sum of values divided by how many there are. For [2, 4, 6], the mean is 4. The median is the middle value after sorting; it is also 4 for these three numbers. If the values are [2, 4, 100], the mean becomes much larger while the median remains 4. Neither summary is universally better. The choice depends on whether rare large values should strongly affect the story.

Spread describes how much values differ. A range is the largest minus the smallest. Variance averages squared distances from a mean; standard deviation is its square root, putting the result back into the original unit. You do not need to calculate these by hand to read a model, but you should know why two datasets with the same average can be very different. A city with temperatures near 20 every day and one alternating between cold and hot may share a mean while demanding different decisions.

02 / THE MODEL

How the idea works.

A proportion is a part divided by a whole. If 8 of 10 messages are useful, the observed proportion is 0.8, or 80%. Probability expresses uncertainty about an event under a model or stated assumptions. It is a number between 0 and 1, but a model's 0.8 estimate is not automatically a well-calibrated 80% real-world chance. Calibration asks whether events assigned about 0.8 actually happen about eight times out of ten over many comparable cases.

A sample is the subset of cases we observed. The population is the wider set about which we want to make claims. A convenient sample may be unrepresentative: messages collected during one holiday week may differ from messages in ordinary weeks. Random sampling helps only when the sampling process can reach the cases that matter. More rows from the same narrow source do not fix a missing population.

Correlation describes a relationship between variables, not proof that one causes the other. Ice cream sales and heat-related illness can rise together because warm weather influences both. A predictor may still use a correlated feature if it is available and stable, but changing that feature may not change the outcome. This difference becomes important when someone wants to use a model to decide what action to take, rather than merely forecast what will happen.

03 / PYTHON, EXPLAINED

Follow the code.

numbers-and-uncertainty.py
from statistics import mean, median, pstdev

values = [2, 4, 100]
print("mean:", mean(values))
print("median:", median(values))
print("spread:", pstdev(values))
print("proportion above 10:", sum(v > 10 for v in values) / len(values))

The import brings three statistical functions into the file. mean adds the three values and divides by three. median sorts conceptually and chooses the middle value, 4. pstdev computes population standard deviation for this particular list; its result is large because 100 is far from the other values. The final expression compares each value with 10, producing booleans. In Python, True contributes 1 when summed, so the numerator is 1 and the proportion is one third.

The example is descriptive, not a prediction. It tells us about three observed numbers. It cannot tell us whether these numbers represent future cases, whether 100 is a valid observation, or why it occurred. Statistics become useful when we connect the arithmetic to a careful definition of what was measured and how the sample was collected.

04 / THE BOUNDARY

What the result does not say.

Many models minimise an average error. A few extreme errors can dominate a squared-error average, while an absolute-error average is less sensitive to them. That is a choice about what failures matter, not only a mathematical detail. We will revisit it when discussing regression metrics.

Numbers also carry units. A model trained on meters cannot safely receive centimeters without conversion. A probability, a score, a count, and a currency amount can all be represented as floating-point numbers, but they have different meanings. Naming those meanings prevents silent mistakes.

05 / KEEP THIS

One clear idea.

Summary numbers describe observed data; their meaning depends on sampling, units, and the decision being made.

THE CODE IN CONTEXT

The ML cookbook

Complete, explained Python workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗Machine learning with Python · From examples to trustworthy models.