使用 Python 中的 statsmodels 进行回归入门
Maarten Van den Broeck
Content Developer at DataCamp
鲷鱼:"好"的模型
mdl_bream = ols("mass_g ~ length_cm", data=bream).fit()

鲈鱼:"差"的模型
mdl_perch = ols("mass_g ~ length_cm", data=perch).fit()

鲷鱼

鲈鱼

鲷鱼

鲈鱼

鲷鱼(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")

使用 Python 中的 statsmodels 进行回归入门