The straight-line model: y = w × x + b
Last week you made predictions from a table by looking for a pattern. The simplest pattern is a straight line: every time x grows by one step, y changes by the same amount. This is the linear model, written y = w × x + b. The input is x, the expected output is y, and w and b are two fixed numbers that describe the line. For hours of study and marks, the picture shows the line y = 10x + 40. With x = 2 hours we get y = 10 × 2 + 40 = 60 marks. In Python the model is one line: y = w * x + b. A linear model is simple, which makes it a good first example of how an AI model works. It is far from the only model, and many real problems need more complicated ones.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | x (hours) | 0 | 1 | 2 | 3 |
| 2 | y (marks) | 40 | 50 | 60 | 70 |
| 3 | change | +10 | +10 | +10 |
1w = 10 2b = 40 3x = 2 4y = w * x + b 5print(y)
60
Using y = 10x + 40, calculate y for x = 0, 1, 4 and 6 and write the answers in a table. Then draw the four points on squared paper and join them with a ruler. Do the points lie on a straight line?