Skip to Content
Learn
Linear Regression
Minimizing Loss

The goal of a linear regression model is to find the slope and intercept pair that minimizes loss on average across all of the data.

The interactive visualization in the browser lets you try to find the line of best fit for a random set of data points:

  • The slider on the left controls the m (slope)
  • The slider on the right controls the b (intercept)

You can see the total loss on the right side of the visualization. To get the line of best fit, we want this loss to be as small as possible.

To check if you got the best line, check the “Plot Best-Fit” box.

Randomize a new set of points and try to fit a new line by entering the number of points you want (try 8!) in the textbox and pressing Randomize Points.

Instructions

Play with the interactive visualization in the browser.

Try to notice what method you, as a human and not a computer (hopefully), use to minimize loss:

  • Do you first get the slope to where it produces lowest loss, and then move the intercept to where it produces lowest loss?
  • Do you create a rough idea in your mind where the line should be first, and then enter the parameters to match that image?
Folder Icon

Sign up to start coding

Already have an account?