包含交互项的预测
和您之前创建的其他回归模型一样,有趣的部分在于进行预测。幸运的是,此处的代码流程与不含交互项时相同——statsmodels 可以在无需额外指示的情况下计算交互项。您只需记住获取解释变量组合的小技巧。
mdl_price_vs_both_inter 已作为拟合好的模型提供,itertools.product 已加载。
本练习是课程的一部分
Python 中级回归:使用 statsmodels
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create n_convenience as an array of numbers from 0 to 10
n_convenience = ____
# Extract the unique values of house_age_years
house_age_years = ____
# Create p as all combinations of values of n_convenience and house_age_years
p = ____
# Transform p to a DataFrame and name the columns
explanatory_data = ____
# Print it
print(explanatory_data)