Get startedGet started for free

Distribution of errors

Almost no real-world process can be predicted perfectly. A desirable outcome is that the error is normally distributed. This means that some actual values will be above your prediction, and some will fall below it. That is, the errors (i.e. the difference between the actual values and predictions) will seem to "float" randomly around zero.

In this exercise, you will analyze results from a pre-built linear model which predicts a police officer's salary. You will then look at the error and see if it is approximately normally distributed. The predictions are a list of values stored in preds, and the actual salaries are a list of values stored in salaries.

This exercise is part of the course

Foundations of Inference in Python

View Course

Exercise instructions

  • Compute the error as the actual salaries minus the predicted salaries.
  • Plot the errors in a histogram.
  • Conduct an Anderson-Darling test of normality for the errors.
  • Find and print the significance_level(s) at which the null hypothesis would be rejected.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Compute the error as actual minus predicted salary
error = ____

# Plot the errors as a histogram
plt.____(____)
plt.show()

# Conduct an Anderson-Darling test using the years of experience
result = ____(____)

# Find where the result is significant
print(result.____[result.____ > result.____])
Edit and Run Code