Draw a candidate line.
Every point gets a prediction from y = mx + b. At first it can be completely wrong. That is the point: the model has a visible place to improve from.
ML from scratch, in the browser
Set a tiny dataset. Calculate the error. Move the line. This is linear regression without a wrapper, so every update has a reason.
A working notebook
y = 0.000x + 0.000
The loop, named
Every point gets a prediction from y = mx + b. At first it can be completely wrong. That is the point: the model has a visible place to improve from.
Each update records a real mean-squared error.
Mean squared error makes large misses matter more. The value is not invented feedback; it is recalculated from the exact points and line in your experiment.
The two gradients say how loss changes when slope or intercept move. Multiply by the learning rate, subtract, repeat. Smaller steps are steadier; oversized steps can miss the valley.
A durable mental model
scikit-learn and PyTorch let you move fast. This lab is not a replacement for them. It is a compact way to connect the convenience of an API call to the predictions, loss, and parameter updates it orchestrates.
Change the data, start from a strange slope, then download the evidence of what happened. A short experiment can make the next training loop feel less like a black box.
Keep the evidence
The source prediction is slope times x plus intercept, and loss averages squared prediction-minus-target residuals. Hypothetical residuals one and three give mean squared error five; residuals zero and two give two. Bars share fifty pixels per mean squared error unit. Squaring makes larger misses contribute disproportionately. Each update subtracts learning rate times current gradient from slope and intercept. Hypothetical gradient two with rates point one and point zero five gives step magnitudes point two and point one. Bars share one thousand pixels per parameter-step magnitude. The sign of the gradient sets direction; smaller rate changes distance, not direction. Intercept gradient is twice the average residual. Hypothetical residuals one and two give gradient three; residuals zero and two give gradient two. Bars share one hundred pixels per gradient magnitude. This educational tool shows actual loss history, learned line, gradients and downloadable predictions from browser computation. Complete native step/export/reset, responsive and first-footer checks preserve all actual run data; full independent scene approval remains separate and no backend model executes.