Live AI/ML Sessions | Outside College & Office Hours | Session Recordings on LMS | Learn Around Your Schedule | Built for Students & Working Professionals
Live AI/ML Sessions | Outside College & Office Hours | Session Recordings on LMS | Learn Around Your Schedule | Built for Students & Working Professionals

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

Feature (x)Target (y)
Actual observations Prediction Residual

Section C

Prediction error and loss

ActualPredictedResidualSquared residual
2.0001.300-0.7000.490
4.0002.100-1.9003.610
5.0002.900-2.1004.410
8.0003.700-4.30018.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. 1. Predictions: (1, 2) → ŷ = 1.300; (2, 4) → ŷ = 2.100; (3, 5) → ŷ = 2.900; (4, 8) → ŷ = 3.700
  2. 2. Residuals: e1 = -0.700; e2 = -1.900; e3 = -2.100; e4 = -4.300
  3. 3. Current MSE: 6.750
  4. 4. Gradient with respect to weight: -14.000
  5. 5. Gradient with respect to bias: -4.500
  6. 6. Weight update: w_new = w − α∂J/∂w = 0.800 − 0.060 × -14.000 = 1.640
  7. 7. Bias update: b_new = b − α∂J/∂b = 0.500 − 0.060 × -4.500 = 0.770
  8. 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.