開始使用免費開始

含交互作用的預測

就像你建立過的其他回歸模型一樣,最有趣的部分是做出預測。幸好,這種情況下的程式流程和沒有交互作用時相同——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)
編輯並執行程式碼