建構含兩個數值解釋變數的模型
你已經看過如何使用一個數值與一個類別型解釋變數來建立模型並進行預測。當有兩個數值型解釋變數時,建模與預測的程式碼基本相同,只是指定要用來預測的解釋變數方式略有不同。
在這裡,你會以附近便利商店數量,以及到最近 MRT 車站距離的平方根,來建模並預測房價。
taiwan_real_estate 已提供平方根轉換後的變數 sqrt_dist_to_mrt_m。itertools.product 也已載入。
本練習屬於課程
使用 Python 的 statsmodels 進行迴歸分析:中級
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Fit linear regression of price vs. no. of conv. stores and sqrt dist. to nearest MRT, no interaction
mdl_price_vs_conv_dist = ____
# See the result
print(mdl_price_vs_conv_dist.params)