All virtual labs
Lab 15 · Artificial Intelligence

AI & Machine Learning

POSTGRADUATE FLAGSHIP · Transformer self-attention →

Eleven machine-learning experiments that genuinely train in your browser — no precomputed results, no libraries. Every model hand-rolls its own math: gradient descent, backpropagation, Lloyd's algorithm, recursive Gini splits, power-iteration eigenvectors, three named optimizers, live convolution feature maps, ridge regression by the normal equations with k-fold cross-validation, and a real Iris classifier with a confusion matrix. Pick an experiment, read the theory, then run the live simulation.

Linear regression via gradient descent

Experiment 01 · supervised learning · mean-squared-error minimisation

Aim

To fit a straight line y = w·x + b to a set of scattered 2-D points by minimising the mean-squared error using batch gradient descent, and to observe how the learning rate controls convergence of the loss curve.

Theory

Linear regression assumes the target is an affine function of the input plus noise. Training searches for the parameters (w, b) that minimise the mean-squared error (MSE) over all n samples. Because MSE is convex and differentiable, we can descend its gradient: at every step we move the parameters a small amount (the learning rate) in the direction of steepest decrease.

prediction y_hat = w·x + b
loss (MSE) L = (1/n) Σ (y_hat_i - y_i)^2
gradients dL/dw = (2/n) Σ (y_hat_i - y_i)·x_i , dL/db = (2/n) Σ (y_hat_i - y_i)
update w ← w - η·dL/dw , b ← b - η·dL/db

The coefficient of determination R² = 1 - SS_res/SS_tot reports the fraction of variance explained; R² = 1 is a perfect fit.

Procedure
  1. Press Sample data to load a noisy linear cloud, or click anywhere on the plot to drop your own (x, y) points.
  2. Set the learning rate with the slider (log scale).
  3. Press Train to run gradient descent continuously, or Step to advance a few epochs at a time.
  4. Watch the purple line rotate into place while the amber MSE curve falls each epoch.
  5. Read the converged weight, bias and R²; try a learning rate that is too high to see the loss diverge.

Gradient descent · MSE loss

Click the plot to drop (x, y) points. Gradient descent fits y = w·x + b by minimising mean-squared error; the line and loss curve update every epoch.

Controls

0.05
weight w
0.000
bias b
0.000
MSE loss
--
epoch
0

R² goodness of fit

--
References
  • Bishop, C. M. Pattern Recognition and Machine Learning, Springer 2006 — Ch. 3, Linear Models for Regression.
  • Hastie, Tibshirani & Friedman. The Elements of Statistical Learning, 2nd ed., Springer 2009 — Ch. 3.
  • Goodfellow, Bengio & Courville. Deep Learning, MIT Press 2016 — Ch. 4-5 on gradient-based optimisation.