Linear Regression

AI Simulator Platform

Linear Regression Visualization

Interactive simulation for OLS, GD, and SGD.

Linear regression estimates a straight-line relationship between an input x and output y.

y = ax + b

Here, a is the slope and b is the intercept. In this simulator, each point you add is a training sample and the model finds the best-fitting a and b.

The model minimizes mean squared error (MSE):

$$ MSE(a,b) = \frac{1}{n}\sum_{i=1}^{n}(y_i-(ax_i+b))^2 $$

Squaring penalizes large errors more strongly and gives a smooth optimization target. Lower loss means a better fit.

  • OLS: Closed-form and one-shot.
  • Batch GD: Uses all samples per epoch, stable but heavier.
  • SGD: Uses shuffled single-sample updates, faster but noisier.

Use the same points and compare learning curves for each method.

  1. Add points or load demo data.
  2. Run OLS first to get a baseline line.
  3. Switch to GD/SGD and tune learning rate and epochs.
  4. Use Test Mode to inspect actual vs predicted values.

Click to add points. Long-press on a point to remove it.


Loss (MSE)
Model
Points: 0
Slope (a): -
Intercept (b): -
R2: -
Last Loss: -
Method Notes
OLS

Closed-form solution from covariance and variance:

$$ a = \frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{\sum (x_i-\bar{x})^2}, \quad b = \bar{y} - a\bar{x} $$