A Complete Linear Model

We saw in the previous lesson we already have a very good model for predicting the petal length of a flower based on its petal width. But let's see if we can improve the model. There are a few ways we can do this. Let's begin by adding the remaining variables to the linear regression equation. To represent these additional variables in the equation let's adjust our notation. Let x_1 represent the petal width, x_2 represent the petal length, and x_3 represent the sepal width. And \beta_i be the corresponding coefficients for each variable, with \beta_0 being the intercept. Then the linear regression equation becomes:

y = \beta_0 + \beta_1 * x_1 + \beta_2 * x_2 + \beta_3 * x_3 + \varepsilon

And in matrix form we collect the variables into a matrix X and the coefficients into a vector \beta = [\beta_0, \beta_1, \beta_2, \beta_3]:

y = X \beta + \varepsilon

In the above code editor we wrapped the estimated coefficients in a np.round to round the coefficients to two decimal places just to make the output easier to read. Next, let's get the predicted values using these estimated coefficients so we can check its performance in terms of the mean squared error.

Awesome, the mean square error is even smaller than before! We improved the model by reducing the MSE from 0.86 to 0.1. That will be the most we improve the model for now, next we will apply linear regression to a different dataset to get some more practice with it in a different context.