Extension: Fitting The Model

1.13. Extension: Fitting The Model#

Consider the following study data.

../../_images/study_plot.png

How do we work out the line of best fit for this data?

Consider the following options:

../../_images/model_options.png

Which of these do you think produces the best fit to the data?

Some of these options (option 1 and 3) are obviously bad fits, but the rest are quite reasonable fits. They way the computer ‘decides’ on the best fit is by selecting the model that has the lowest mean square error on the data it has been provided (we call this data the training data).

Click below to see what the mean square error (MSE) is for each of the options.

Expand
  • Option 1: 324

  • Option 2: 21

  • Option 3: 489

  • Option 4: 6

  • Option 5: 89

From these results, option 4 has the lowest MSE on the training data, hence of the 5 models presented here, option 4 is considered the best.

When you call .fit, the computer is calculating the best model intercept and gradient such that it achieves the lowest MSE on the training data.