cloudsandai
Simple Linear Regression: An Interactive Learning Lab
Understand how a machine learning model learns a line from data, calculates errors, and improves its predictions using gradient descent.
Section A
Understand the data
The feature is the input variable, and the target is the value the model tries to predict. Here, the input is hours studied and the target is an exam score.
| Feature (x) | Target (y) | Actions |
|---|---|---|
Dataset is valid and ready to train.
Section B
Scatter plot and prediction line
Section C
Prediction error and loss
| Actual | Predicted | Residual | Squared residual |
|---|---|---|---|
| 2.000 | 1.300 | -0.700 | 0.490 |
| 4.000 | 2.100 | -1.900 | 3.610 |
| 5.000 | 2.900 | -2.100 | 4.410 |
| 8.000 | 3.700 | -4.300 | 18.490 |
MSE
6.750
Average residual
-2.250
Mean squared error emphasises larger mistakes by squaring residuals before averaging. It is not the same as the average residual.
Section D
Gradient descent
Training status
Ready for training.
Iteration: 0
Loss change: 0.000
Gradient w: -14.000
Gradient b: -4.500
Current loss: 6.750
Next update: w 1.640 | b 0.770
Section E
Loss versus iteration
Initial loss: 6.750
Current loss: 6.750
What happens during one gradient descent step?
- 1. Predictions: (1, 2) → ŷ = 1.300; (2, 4) → ŷ = 2.100; (3, 5) → ŷ = 2.900; (4, 8) → ŷ = 3.700
- 2. Residuals: e1 = -0.700; e2 = -1.900; e3 = -2.100; e4 = -4.300
- 3. Current MSE: 6.750
- 4. Gradient with respect to weight: -14.000
- 5. Gradient with respect to bias: -4.500
- 6. Weight update: w_new = w − α∂J/∂w = 0.800 − 0.060 × -14.000 = 1.640
- 7. Bias update: b_new = b − α∂J/∂b = 0.500 − 0.060 × -4.500 = 0.770
- 8. Result: w = 1.640, b = 0.770, loss = 0.274
The gradient tells us the direction of steepest increase in error, so subtracting it moves the model toward a lower loss. The learning rate controls the step size.
Section G
Least squares comparison
Gradient descent is one method for minimizing the least-squares objective. The closed-form solution gives the exact minimum when the denominator is not zero.