Heteroscedasticity occurs when residuals do not have a consistent spread across predicted values. A residual plot should look like an even cloud around zero; visible shapes or trends suggest uneven prediction accuracy. section 9.1.2
Diagnose and respond to inconsistent residual spread by:
- Plotting residuals against predicted values and checking for patterns, trends, or changing spread. section 9.1.2
- Checking a residual histogram; linear regression residuals are expected to be normally distributed. section 9.1.2
- Reviewing whether the formula is appropriate, removing erroneous extreme outliers, and considering missing explanatory variables. section 9.1.2
housing_prices["residuals"] = model.resid
housing_prices["predicted_values"] = model.predict() #1
plt.scatter(
housing_prices["predicted_values"],
housing_prices["residuals"]
) #2
plt.axhline(y=0, color= "black", linestyle="-") #3
Use the residual-versus-predicted-values listing to reproduce the central diagnostic plot for a housing-price regression. section 9.1.2



