Exercise

Least-Squares with `numpy`

The formulae below are the result of working through the calculus discussed in the introduction. In this exercise, we'll trust that the calculus correct, and implement these formulae in code using numpy.

$$ a_{1} = \frac{ covariance(x, y) }{ variance(x) } $$ $$ a_{0} = mean(y) - a_{1} mean(x) $$

Instructions

100 XP
  • Compute the means and deviations of the two variables x, y from the preloaded data.
  • Use np.sum() to complete the least-squares formulae, and use them to compute the optimal values for a0 and a1.
  • Use model() to build the model values y_model from those optimal slope a1 and intercept a0 values.
  • Use the pre-defined compute_rss_and_plot_fit() to visually confirm that this optimal model fits the data.