Once we’ve calculated the fitted values and residuals for a model, we can check the normality and homoscedasticity assumptions of linear regression.

Normality assumption

The normality assumption states that the residuals should be normally distributed. To check this assumption, we can inspect a histogram of the residuals and make sure that the distribution looks approximately normal (no skew or multiple “humps”):

plt.hist(residuals) plt.show()

symmetric histogram with a single hump

These residuals appear normally distributed, leading us to conclude that the normality assumption is satisfied.

If the plot instead looked something like the distribution below (which is skewed right), we would be concerned that the normality assumption is not met:

histogram which is right skewed: there is a longer tail on the right side than the left

Homoscedasticity assumption

Homoscedasticity is a fancy way of saying that the residuals have equal variation across all values of the predictor variable. A common way to check this is by plotting the residuals against the fitted values.

plt.scatter(fitted_values, residuals) plt.show()

scatter plot with a splatter of randomly distributed points

If the homoscedasticity assumption is met, then this plot will look like a random splatter of points, centered around y=0 (as in the example above).

If there are any patterns or asymmetry, that would indicate the assumption is NOT met and linear regression may not be appropriate. For example:

scatter plot with a funnel-shaped pattern of points



Your code to calculate the residuals and fitted values for the model of score predicted by hours studied is provided for you in script.py. Plot a histogram of the residuals to check the normality assumption. Is this assumption met?


Now, check the homoscedasticity assumption by plotting the residuals against the fitted values (fitted_values on the x-axis and residuals on the y-axis). Is this assumption met?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?