We throw a ball into the air and measure its height at different times. We want to predict where the ball will be at 1.5 seconds.
Because gravity pulls the ball down, the path is an arc (parabola), not a straight line. Therefore, Simple Linear Regression will fail here. We need Polynomial Regression (Degree 2).
| Time in Seconds ($x$) | Height in Meters ($y$) |
|---|---|
| 0 | 2 |
| 1 | 12 |
| 2 | 12 |
| 3 | 2 |
A straight line equation looks like $y = mx + b$. A polynomial (degree 2) equation looks like:
Here, $w_0$, $w_1$, and $w_2$ are the weights we need to find.
The computer (or a complex manual calculation using matrices) solves for the weights that minimize the error. For this perfect physics example, the result is:
Height = -5(Time)² + 15(Time) + 2
Let's predict the height at 1.5 seconds (exactly halfway between measurements):
$$ y = -5(1.5)^2 + 15(1.5) + 2 $$ $$ y = -5(2.25) + 22.5 + 2 $$ $$ y = -11.25 + 24.5 $$ $$ y = 13.25 ext{ meters} $$
The model correctly predicts that the ball peaks between 1 and 2 seconds, reaching higher than the measured points of 12m. A straight line model would have predicted it was just staying flat or going in one direction!