Introduction to Regression with statsmodels in Python
Maarten Van den Broeck
Content Developer at DataCamp
Bream: the "good" model
mdl_bream = ols("mass_g ~ length_cm", data=bream).fit()

Perch: the "bad" model
mdl_perch = ols("mass_g ~ length_cm", data=perch).fit()

Bream

Perch

Bream

Perch

Bream

Perch

sns.residplot(x="length_cm", y="mass_g", data=bream, lowess=True)
plt.xlabel("Fitted values")
plt.ylabel("Residuals")

from statsmodels.api import qqplot
qqplot(data=mdl_bream.resid, fit=True, line="45")

model_norm_residuals_bream = mdl_bream.get_influence().resid_studentized_internalmodel_norm_residuals_abs_sqrt_bream = np.sqrt(np.abs(model_norm_residuals_bream))sns.regplot(x=mdl_bream.fittedvalues, y=model_norm_residuals_abs_sqrt_bream, ci=None, lowess=True)plt.xlabel("Fitted values") plt.ylabel("Sqrt of abs val of stdized residuals")

Introduction to Regression with statsmodels in Python