Module 1: Data, models and the maths you need · Lesson 1.3 · about 20 min
Functions, slopes and straight lines
A function turns an input into an output, and a straight line is the simplest one: y = mx + c. Drag two points to see slope and intercept, the two numbers every linear model learns.
Module 1 · about 20 minutes · school maths. You’ll be able to read and write the equation of a straight line, work out a slope from two points, and say what slope and intercept mean in a real problem.
1. Why this matters
The first model in this course, linear regression (Module 3), is a straight line. Logistic regression (Module 4) bends a straight line into an S. Each neuron in a neural network (Module 9) starts with a straight-line sum. If you are at home with , you already understand the core of all three.
2. A function is a rule from input to output
A function is like a vending machine: you put one thing in, and exactly one thing comes out. We write and say “y is f of x”. Here is the input, is the rule and is the output. Examples:
- Taxi fare from distance: (dollars, for km).
- Area of a square from its side: .
- A trained model from a home’s floor area to its predicted price.
A graph shows every input along the flat x-axis and its output up the tall y-axis.
3. The straight line
A straight line has the form
- is the slope (also called the gradient): how much goes up when goes up by 1.
- is the intercept: the value of when , where the line crosses the y-axis.
Think of a phone plan: a fixed monthly fee (the intercept) plus a price per gigabyte (the slope). Use no data and you still pay the fee; each gigabyte adds the same amount.
Drag the two points below. The triangle shows the rise (how far up) and the run (how far across).
Things to notice:
- Make the line flatter: the slope gets closer to 0. A flat line means x makes no difference to y.
- Make it go down to the right: the slope turns negative.
- Line the two points up vertically: the run is 0 and the slope can’t be worked out (you would divide by zero).
4. Slope from two points
For two points and on the line:
The second formula comes from putting one point into and solving for . Watch it with a courier’s two trips:
Maths and principle
Principle: a straight line changes at a constant rate. Its slope is the same between any two of its points.
Equation: , with and .
In machine learning notation: the same line is usually written . The slope becomes a weight (how much this input matters) and the intercept a bias (the starting value). With many inputs it becomes , which Lesson 1.4 writes in one short line with a dot product.
Analogy: a phone plan: a fixed monthly fee (the intercept) plus a price per gigabyte (the slope).
Try it: a line passes through (2, 7) and (6, 15). Find and . (; ; so .)
- m or w (slope, weight)
- How much the output changes for each one-unit step in the input. It has units: output units per input unit.
- c or b (intercept, bias)
- The output when the input is 0: where the line starts.
- Rise ÷ run
- How far up divided by how far across, between any two points on the line.
- Physical meaning
- A slope is a rate you can feel: dollars per kilometre, minutes per stop, $1,000s per square metre. A steep slope means the input matters a lot; a flat one means it hardly matters at all.
5. Reading a slope in the real world
The slope always has units: units of y per unit of x.
- A price model with slope 3.1, where x is floor area in m² and y is price in $000, says each extra square metre adds about $3,100.
- A slope of −1.5 for a used car’s value in $000 against its age in years says it loses about $1,500 a year. It is negative because the value goes down as age goes up.
“The intercept always means something real.” Not always. A price model may say a flat of 0 m² costs $90,000, but nobody sells a flat with no floor. The intercept is just where the line has to start so that it fits the data that does exist. Only read meaning into it when x = 0 is a sensible case, as with the courier’s loading time.
6. Curves are not straight, but up close they almost are
Most functions are curves, such as . A curve has no single slope: it is steeper in some places than others. But zoom in far enough on any smooth curve and the piece you see looks straight, just as the Earth looks flat from where you stand. The slope of that tiny straight piece is the derivative, the idea in Lesson 1.5, and the tool that lets models learn.
7. Worked example
Made-up numbers. A delivery firm notes that a 4 km trip took 17 minutes and a 10 km trip took 35 minutes. Assuming a straight line:
- Slope: minutes per km.
- Intercept: minutes (time for loading and parking, before any driving).
- Model: time = 3 × km + 5. A 7 km trip: 3 × 7 + 5 = 26 minutes.
With only two points the line goes through both exactly. With 200 real trips the points scatter and no line hits them all. Finding the best line through many points is Lesson 3.2.
8. Practice
- Find the line through (0, 4) and (5, 14).
- A line has slope −2 and passes through (3, 1). What is at ?
- In , x is hours of sunshine and is ice creams sold (hundreds). What does 0.4 mean?
Answers
- , : .
- From x = 3 to 5 is a run of 2, so the rise is −2 × 2 = −4: y = 1 − 4 = −3.
- Each extra hour of sunshine goes with about 40 more ice creams.
Try it on your own data: plot any formula in the graphing calculator, or fit a line to your own points with best-fit line.
New words: function, slope or gradient (rise over run), intercept, weight and bias (slope and intercept in machine learning).
- A function turns each input into exactly one output: y = f(x).
- A straight line is y = mx + c: slope m (change per step of x) and intercept c (value at x = 0).
- Slope from two points is rise ÷ run; then c = y₁ − m x₁.
- In machine learning the slope is a weight w and the intercept a bias b.
- Slopes have units, and an intercept only means something if x = 0 makes sense.
Check yourself
Sources
- Strang, G. (2016), Introduction to Linear Algebra, 5th ed., Wellesley-Cambridge Press, Chapter 1
- James, G., Witten, D., Hastie, T., Tibshirani, R. and Taylor, J. (2023), An Introduction to Statistical Learning with Applications in Python, Springer, Chapter 3 (simple linear regression) https://www.statlearning.com/
- Goodfellow, I., Bengio, Y. and Courville, A. (2016), Deep Learning, MIT Press, Section 5.1.4 (linear regression as w·x + b) https://www.deeplearningbook.org/
Your ticks stay in this browser. Save them as a file on the course home.
Updated 2026-11-22. Numbers in the examples are made up to show the idea unless a source is given. Simulations run in your browser; nothing you type is sent anywhere.