# 3.Homoscedasticity in the Residuals

`#Graph our residuals against our predictions, this will give us a sense if our model is off for certain priced homesplt.scatter(df_predictions["price_Predicted"], df_Regression_No_Outliers_With_ScaledData["price_Residuals"])plt.xlabel("Predicted Price")plt.xticks(ticks=(300000, 500000, 700000, 900000, 1200000),labels= ('\$300k', '\$500k', '\$700k', '\$900k',\$1.2M'))plt.ylabel("Residual")plt.yticks(ticks=(-300000, -100000, 0, 300000, 500000),labels= ('\$-300k', '\$-100k', '\$0k', '\$300k','\$500k'))plt.plot(df_predictions["price_Predicted"], [0 for i in range(len(df_predictions["price_Predicted"]))],color="r");plt.show()`
`# het_breuschpagan suggests heteroscedasticity in the data P-value> .05, null = homoscedasticity vs. heteroscedasticityfrom statsmodels.compat import lzipimport statsmodels.stats.api as smsname = ['LM Statistic', 'LM-Test p-value', 'F-Statistic', 'F-Test p-value']test = sms.het_breuschpagan(model.resid, predictors_int)lzip(name,test)`

# 4. Normality in Distribution of Residuals

`# Import appropriate librariesimport statsmodels.api as smimport scipy.stats as statsimport pylab#Plot Histogram and QQPfig,axes=plt.subplots(1,2)sns.histplot(model.resid,ax=axes)sm.graphics.qqplot(data=model.resid, dist=stats.norm, line='45', fit=True, ax=axes)axes.set_title('Histogram of Residuals')axes.set_xlabel("Residuals")axes.set_title('QQP of Residuals')axes.set_ylabel("Residual Z Scores")pylab.show()`

--

--