拟合平行斜率线性回归
在课程 Introduction to Regression with statsmodels in Python 中,您已经学习了只含一个解释变量的线性回归模型。在很多情况下,仅使用单个解释变量会限制预测的准确度。要真正掌握线性回归,您需要能够拟合包含多个解释变量的回归模型。
当包含 1 个数值型解释变量和 1 个分类型解释变量时,由于预测曲线的形状,这类模型有时被称为"平行斜率"线性回归——下一道练习会详细介绍。
这里,您将再次使用台湾房地产数据集。回忆各变量的含义。
| Variable | Meaning |
|---|---|
dist_to_mrt_station_m |
距离最近 MRT 地铁站的距离(米)。 |
n_convenience |
步行可达范围内的便利店数量。 |
house_age_years |
房龄(年),分为 3 组。 |
price_twd_msq |
单位面积房价(新台币/平方米)。 |
taiwan_real_estate 已提供。
本练习是课程的一部分
Python 中级回归:使用 statsmodels
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import ols from statsmodels.formula.api
____
# Fit a linear regression of price_twd_msq vs. n_convenience
mdl_price_vs_conv = ____
# Print the coefficients
print(____)