使用 ols() 的线性回归
虽然 sns.regplot() 可以显示线性回归的趋势线,但它不会把截距和斜率作为变量提供,也不允许您将模型结果当作变量来使用。也就是说,有时您需要自己运行线性回归。
现在来运行您的第一个模型!
taiwan_real_estate 已提供。TWD 是新台币(Taiwan dollars)的缩写。
另外,本练习及本课程后续练习中,将按需导入并设置以下包的别名:matplotlib.pyplot 为 plt,seaborn 为 sns,以及 pandas 为 pd。
本练习是课程的一部分
使用 Python 中的 statsmodels 进行回归入门
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the ols function
from ____ import ____
# Create the model object
mdl_price_vs_conv = ____(____, data=____)
# Fit the model
mdl_price_vs_conv = ____.____
# Print the parameters of the fitted model
print(____.____)