Lesson 3.3 · Stage 03: The maths behind machine learning
Maths chapter 1: Warm-up: the school algebra you need
Everything later is built from six school ideas: variables, equations, functions, graphs, powers, and the summation sign.
Everything later is built from six school ideas: variables, equations, functions, graphs, powers, and the summation sign.
1.1 Variables and equations
A variable is a letter that stands for a number we don’t know yet, such as x. An equation says two things are equal. Solving it means finding the number that makes it true.
Worked example. Solve 3x + 5 = 20.
- Subtract 5 from both sides: 3x = 15.
- Divide both sides by 3: x = 5.
- Check: 3 × 5 + 5 = 20. Correct.
Rule to remember: whatever you do to one side, do to the other.
1.2 Functions
A function is a machine: a number goes in, a number comes out. We write f(x) = 2x + 1. Put in x = 3 and you get f(3) = 2 × 3 + 1 = 7.
A machine learning model is just a function. Data goes in, a prediction comes out.
1.3 Graphs and straight lines
A graph has an x-axis (left–right) and a y-axis (up–down). A point is written (x, y). The point (2, 5) is 2 steps right and 5 steps up.
Every straight line can be written as:
- m is the slope: how much y goes up when x goes up by 1.
- c is the intercept: where the line crosses the y-axis.
The slope between two points (x₁, y₁) and (x₂, y₂) is:
Worked example. Points (1, 3) and (4, 9): m = (9 − 3) ÷ (4 − 1) = 6 ÷ 3 = 2. For each step right, the line goes 2 up.
Why ML needs it: linear regression, the first ML model, is literally y = mx + c.
1.4 Powers, square roots, e and log
- Power: 3² = 3 × 3 = 9 and 2³ = 2 × 2 × 2 = 8. A square is never negative: (−3)² = 9.
- Square root: √16 = 4 because 4 × 4 = 16. It undoes squaring.
- e is a special number, about 2.718. It appears in the bell curve and in many ML formulas, the way π appears in circles.
- log undoes powers: if 10² = 100, then log₁₀(100) = 2. In ML, “log” usually means log base e, written ln.
1.5 The summation sign Σ
Σ (Greek capital sigma) means “add them all up”. It saves writing long sums.
Read it as: “let i run from 1 to 4, and add up each i”. Another example: if you have marks x₁ = 6, x₂ = 8, x₃ = 10, then Σ xᵢ = 24 and the average is 24 ÷ 3 = 8.
Why ML needs it: every “total error over all data points” is written with Σ.
Try it
- Solve 4x − 7 = 13.
- If f(x) = 3x − 2, find f(4).
- Find the slope of the line through (1, 2) and (3, 8).
- Work out the sum of i² for i = 1 to 3.
- What are √49 and 2⁵?