开始使用免费开始使用

使用平行斜率模型进行预测

虽然 seaborn 可以用 sns.regplot() 自动显示模型预测,但若要获取这些数值以便编程使用,您需要自己计算。

与只有一个解释变量时相同,工作流程分两步:先创建包含解释变量的 DataFrame,然后添加一列预测值。

taiwan_real_estate 可用,mdl_price_vs_both 是已拟合的模型。seabornols()matplotlib.pyplotpandasnumpy 已按默认别名加载。本课程其余部分也将保持这一设置。 另外,ìtertools.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(explanatory_data)
编辑并运行代码