Percentages let you compare shares of different totals by putting them all out of 100. They're also how almost every result in machine learning is reported: accuracy, error rate, how much better a new model is. This lesson covers the three forms of one number, percent of an amount, percentage change, and the difference between a change in percent and a change in percentage points, which trips up headlines and reports alike.
What you'll be able to do
Move between fractions, decimals and percentages, and find a percent of an amount
Work out a percentage change from the old value, and tell it apart from percentage points
Write percentages as decimals in Python, and show them with :.1%
Report a model's accuracy and error rate, and compare two models honestly
Quick check
Have a guess before you start. A shop cuts a price by 50%, then raises the new price by 50%. Compared with where it started, the price is now…
Back where it started
Higher than at the start
Lower than at the start
It depends on the price
Show the answer
Lower than at the start
From 100, a 50% cut gives 50. A 50% rise on 50 adds 25, giving 75. The second 50% was of a smaller amount, so the price ends lower.
The math: per hundred
Purpose. Which is the bigger share: 3 out of 20, or 14 out of 100? Different totals make shares hard to compare. A percentage rewrites every share out of the same total, 100, so they line up.
Percent means per hundred. 35% is 35 per hundred: 35/100, or 0.35. So a fraction, a decimal and a percentage are three ways to write one number:
fraction
decimal
percentage
1/2
0.5
50%
3/4
0.75
75%
3/20
0.15
15%
To go from a decimal to a percentage, times by 100. To go back, divide by 100. So 3 out of 20 is 15%, which beats 14 out of 100.
Quick check
From the last lesson: in 0.07, the 7 is in which place?
Tenths, so 0.07 is 70%
Thousandths, so 0.07 is 0.7%
Ones, so 0.07 is 7
Hundredths, so 0.07 is 7%
Show the answer
Hundredths, so 0.07 is 7%
The first place after the point is tenths, the second is hundredths. 0.07 is 7 hundredths, and 7 per hundred is 7%.
A percent of an amount. To find 20% of 50, turn the percentage into a decimal and multiply: 0.2 × 50 = 10. "Of" means multiply, just as it did with fractions.
Percentage change compares a change with where you started:
change %=oldnew−old×100
In plain words: find how much it changed, divide by where it started, then times 100.
Watch it work for a club that grew from 40 members to 50. The two bars show the old and new sizes. The picture above them cuts the old 40 into 100 equal squares, so the percentage is how many squares the change fills.
Try it now
Step through, then set the old value to 50 and the new value to 40 and press Use these numbers: the same 10 members, a different percentage, because the hundred-square is now cut from 50.
Percentage points. When both numbers are already percentages, a change can be described two ways. Say a pass rate goes from 40% to 50%. The gap is 10 percentage points: plain subtraction on the 0 to 100 scale. The percentage change is 10 ÷ 40 × 100 = 25%. Both are true, but they answer different questions. A careful report says which one it means.
Now the opening question. Cutting 100 by 50% gives 50. Raising 50 by 50% adds half of 50, which is 25. That gives 75. The second 50% was of a smaller amount, so the price ends lower than it started.
Quick check
A pass rate rises from 20% to 30%. Which statement is right?
It rose 30%, from 20 to 30 points
It rose 10 points, a 50% rise
It rose 50 points, a 10% rise
It rose 10%, which is 10 points
Show the answer
It rose 10 points, a 50% rise
The gap on the 0 to 100 scale is 30 − 20 = 10 points. Compared with the start, 10 ÷ 20 × 100 = 50%.
Shortcuts for checking. 10% of anything is a tenth: move the point one place left, so 10% of 80 is 8. From there, 5% is half of 10%, 20% is double it, and 1% is a tenth of it. So 15% of 80 is 8 + 4 = 12. And 35% of 60 is three lots of 6, plus 3, which makes 21. These are worth knowing even with Python on hand. They tell you at a glance whether a printed answer is the right size.
In your own words
In your own words: why does a 50% cut followed by a 50% rise leave a price lower than it started?
Write a sentence or two, then compare it with a good answer in the lesson.
In Python: percentages are decimals in disguise
Purpose. In Python, the % sign means remainder, as you saw in lesson 2. So code holds a percentage as a decimal, and shows it as a percentage only when it's printed.
It runs right here in your browser, with nothing to install.
The last line uses a format made for this: :.1% times the number by 100, shows 1 decimal place, and adds the sign. A percent of an amount is the percentage divided by 100, times the amount:
A percentage change is three short lines, the same steps as the flow:
old = 40
new = 50
change = new - old
print(change / old * 100)
A named mistake: multiplying by the number in front of %. 20% of 50 isn't 20 × 50. That gives 1000, twenty times the whole price. The 20 means 20 hundredths, so divide it by 100 first:
print(20 * 50) # wrong: 20 times the priceprint(20 / 100 * 50) # right: 20 hundredths of the price
A quick sense check catches it: any percent under 100 of an amount must give less than the amount.
Worked example
Worked example: a month of growth
A reading app had 1,250 users in May and 1,400 in June. Work out the change, the percentage change, and 15% of June's users.
may = 1250
june = 1400
change = june - may
pct = change / may * 100print("change:", change)
print(f"percentage change: {pct:.1f}%")
print("15% of June:", 15 / 100 * june)
In the lesson you can change this and run it.
The change is 150 users. Divided by May's 1,250, the starting value, that's 0.12, and times 100 gives 12.0%. The last line turns 15% into 15/100 before multiplying, so it gives 210 users, well under the 1,400 total, which passes the sense check. Inside the print, "15%" is just text in quotes, so Python doesn't treat it as a remainder.
score × 100 is 87.5, shown to 1 place with a % added. round(87.5) is a tie, and Python rounds ties to the even neighbor, 88.
Quick check
Which line finds 8% of total?
8 * total
8 / 100 * total
total / 8
8 % total
Show the answer
8 / 100 * total
8% is 8 hundredths, so divide by 100 and multiply by the total.
Changes as multipliers. A 20% rise keeps all of the price and adds 0.2 of it, so it's the same as times 1.2. A 20% cut keeps 0.8 of it, so it's times 0.8. Step through the code below and watch each percentage turn into a plain multiplier before it touches the price.
This view makes the opening question easy. A 50% cut is times 0.5 and a 50% rise is times 1.5, so the two together are times 0.5 × 1.5 = 0.75: the price ends at 75% of where it started, whatever it was. It also shows how to undo a change: divide by the multiplier.
print(0.5 * 1.5) # a 50% cut, then a 50% rise
up = 50 * 1.2# a 20% riseprint(up * 0.8) # a 20% cut doesn't undo itprint(up / 1.2) # dividing by 1.2 does
Drill
Three everyday percentages
Set as_pct to part out of whole as a percentage, tip to 15% of bill, and rise to the percentage change from old to new. Each starter line has one slip.
part = 18
whole = 24
bill = 60
old = 120
new = 150
as_pct = part / whole
tip = 15 * bill
rise = (new - old) / new * 100print(as_pct, tip, rise)
In the lesson, your code is checked as you write it.
In your own words
Why does Python code write percentages as decimals?
Write a sentence or two, then compare it with a good answer in the lesson.
In AI and ML: accuracy, error rate and points
Purpose. Almost every result in machine learning is a percentage: how often the model is right, how often it's wrong, and how much better a new model is.
The most common metric is accuracy: the share of examples the model got right. If the sign reader gets 912 of 1,000 test signs right, its accuracy is 91.2%. The flip side is the error rate, the share it got wrong:
error rate=1−accuracy
In plain words: whatever share it didn't get right, it got wrong. 91.2% right means 8.8% wrong.
right = 912
total = 1000
accuracy = right / total
print(f"accuracy {accuracy:.1%}, error rate {1 - accuracy:.1%}")
Quick check
What does this print?
acc = 0.95print(round(1 - acc, 2))
0.5
0.95
0.05
5
Show the answer
0.05
1 − 0.95 is a hair off 0.05 in floats, and rounding to 2 places tidies it to 0.05: a 5% error rate.
In the real tools. In PyTorch, the library most models are built with, the model's answers and the right answers are kept as tensors, and accuracy is one line. Here are eight test signs, with each kind of sign stored as a number (0, 1 or 2); the reader gets seven of them right:
Points versus percent, in ML. A new sign reader goes from 90% to 95% accurate. That's 5 percentage points, which sounds small. But look at the errors: the error rate falls from 10% to 5%, so the model now makes half as many mistakes. For a reader of a million signs a day, that's 50,000 fewer wrong signs.
When accuracy is already high, comparing error rates shows progress more honestly than points of accuracy do.
Quick check
Model A is 98% accurate and model B is 99%. How do their errors compare?
They're about the same, 1 point apart
B makes 99% fewer errors than A
B makes 1% fewer errors than A
B makes half as many errors as A
Show the answer
B makes half as many errors as A
A's error rate is 2% and B's is 1%. Going from 2% to 1% halves the errors, a 50% fall, though accuracy rose only 1 point.
Drill
Compare two sign readers
Two sign readers were tested on 2,000 signs. Model A got 1,840 right and model B got 1,920. Set acc_a and acc_b to their accuracies as decimals, points to the gap in percentage points, and fewer to the percentage fall in errors from A to B, as a positive number.
31Formulas with fractions: clear them firstFreeClearing denominators, cross-multiplying, a letter in the bottom, and reciprocal formulas like 1/R = 1/R₁ + 1/R₂.35 min
37Inverse functions, lines and scalingFreeUndoing a function by making x the subject, domains that allow it, line forms, and unscaling predictions.40 min
38Sequences and sums: find n, a, d and rFreeEvery letter of the arithmetic and geometric formulas as the subject, and an average's window from its decay.40 min
40Review: rearrange anything (algebra)FreeBroken rearrangements to fix, mixed practice from the whole algebra block, a strategy chart, and its formula sheet.35 min
41Coordinates and distanceFreePoints as (x, y), Pythagoras, distance in any number of coordinates, and nearest neighbors.42 min
42Angles, degrees and radiansFreeMeasuring a turn, converting units, arcs, and the angle between two arrows.36 min
43Sine and cosineFreeAcross and up: right triangles, the unit circle, and directions and rotations.42 min
44Waves: height, speed and shiftFreeAmplitude, period and phase, sampling a wave, and position codes in transformers.37 min
68Vector equations: rearranging with arrowsFreeSolving for a vector or a scale, recovering a gradient from two weight snapshots, and an angle from a dot product.40 min
87Counting: choices, orders and groupsFreeThe counting principle, factorials, ordered picks and groups, and why attention's cost grows with the square of the length.43 min
88Probability: from counts to chancesFreeEqually likely outcomes, the complement, distributions, seeded simulation, and a next-word model.43 min
89Combining events: and, or, independentFreeThe or rule, independence, probability trees, drawing with and without replacement, and chains of steps.42 min
100Maximum likelihoodFreeLikelihoods as products, log-likelihoods as sums, grid search, underflow, and the negative log-likelihood loss.45 min
101Linear regression: the best lineFreeResiduals, least squares by formula, three roads to one line, the matrix form, and train versus test error.45 min
109One neuron, start to finishFreeWeighted sum, activation, loss, slopes and update, by hand and in code, and what one straight line can and can't split.45 min
111Training a small networkFreeThe backward pass in matrix form, gradient checks, a full training loop, and reading loss curves.45 min
112The same network in PyTorchFreenn.Sequential with the NumPy weights loaded, the same loss and slopes, then SGD and mini-batches.45 min
113Attention as matrix mathFreeScaled dot-product scores, the causal mask, a row-by-row softmax, and blending value vectors.45 min
114Residual connections and layer normFreeAdding the input back and why its slope keeps learning alive, layer norm by hand, and add and norm.40 min
115A transformer block, start to finishFreeA sentence through embeddings, attention, add and norm, a small network and next-word scores, every shape named.45 min
117Final test: transpose any formulaFreeSlips to fix from every topic, mixed practice of every kind of rearranging, the strategy chart and the full sheet.45 min
Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.
See the course →
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write