開始使用免費開始

使用平行斜率模型進行預測

雖然 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)
編輯並執行程式碼