Get startedGet started for free

Assessing model performance

1. Assessing model performance

The big benefit of using more than one explanatory variable in a model is that you can sometimes get a better fit than when you use a single explanatory variable.

2. Model performance metrics

In the last course, you saw two metrics for measuring model performance: the coefficient of determination, and the residual standard error. The coefficient of determination, sometimes known as the R-squared value, measures how good the regression's prediction line fits the observed values, and a larger number is better. The residual standard error, sometimes abbreviated to RSE, is - loosely speaking - the typical size of the residuals. Let's see if these metrics improve when both explanatory variables are included in the fish model.

3. Getting the coefficient of determination

To easily get the coefficient of determination, load the dplyr and broom packages. Recall that broom's glance function retrieves model-level metrics as a data frame. Then dplyr's pull function can be used to extract the metric we want. The coefficient of determination is called r-dot-squared. For the mass versus species model, the coefficient of determination is zero-point-seven-two, where zero is the worst possible fit and one is a perfect fit. For the mass versus length model, the coefficient of determination is better, at zero-point-eight-two. For the mass versus both model, the coefficient of determination is even higher, at zero-point-nine-seven. Using this metric, the model with both explanatory variables is the best one, since it has the highest coefficient of determination.

4. Adjusted coefficient of determination

Adding more explanatory variables often increases the coefficient of determination for a model, but there is a problem. Including too many explanatory variables in your model can lead to a phenomenon called overfitting. That's when your model is optimized to provide the best fit for that particular dataset, but no longer reflects the general population. In this case, the model would be overfit if it performed well on this fish dataset, but badly on a different fish dataset. A variant metric called adjusted coefficient of determination includes a small penalty term for each additional explanatory variable to compensate for this effect. Its a better metric than the plain coefficient of determination. Its equation is based on the plain coefficient of determination, the number of observations, and the number of explanatory variables, including interactions. The penalty is big enough to worry about if the plain coefficient of determination is small, or if the number of explanatory variables is a sizable fraction of the number of observations. To get this metric, we retrieve the adj-dot-r-dot-squared element from the glanced model.

5. Getting the adjusted coefficient of determination

To see the effect of penalization, let's look at the unadjusted and adjusted coefficients side-by-side. Since each model only contains one or two explanatory variables, the effect is tiny.

6. Getting the residual standard error

The code to get the residual standard error is the same as before, but this time we pull out sigma. The mass versus species model has an RSE of just over three hundred. The mass versus length model has an RSE of about one hundred and fifty. Finally, the mass versus both model has an RSE of just over one hundred, meaning that it typically gets the mass wrong by about one hundred grams. Since that number is the lowest of the three, by this metric, the mass versus both model is best. That means that all metrics indicate that the model with two explanatory variables is better than the models with just one explanatory variable.

7. Let's practice!

Your turn to look at some model metrics.