開始使用免費開始

具可理解係數的交互作用

前一個含交互作用項的模型,其係數較難解讀。為了更清楚說明模型在預測什麼,你可以重新表述模型,讓輸出的係數更容易理解。為了進一步釐清,你也可以把結果拿來和按房齡分組建立的模型比較(mdl_0_to_15mdl_15_to_30mdl_30_to_45)。

taiwan_real_estatemdl_0_to_15mdl_15_to_30mdl_30_to_45 已可使用。

本練習屬於課程

使用 Python 的 statsmodels 進行迴歸分析:中級

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Model price vs. house age plus an interaction, no intercept
mdl_readable_inter = ____

# Print the coefficients for mdl_0_to_15
print("mdl_0_to_15 coefficients:", "\n", ____)

# Print the coefficients for mdl_15_to_30
print("mdl_15_to_30 coefficients:", "\n", ____)

# Print the coefficients for mdl_30_to_45
print("mdl_30_to_45 coefficients:", "\n", ____)

# Print the coefficients for mdl_readable_inter
print("\n", "mdl_readable_inter coefficients:", "\n", mdl_readable_inter.params)
編輯並執行程式碼