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.
- Add points or load demo data.
- Run OLS first to get a baseline line.
- Switch to GD/SGD and tune learning rate and epochs.
- Use Test Mode to inspect actual vs predicted values.
Click to add points. Long-press on a point to remove it.
Loss (MSE)
Model
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} $$