開始使用免費開始

使用 ols() 的線性迴歸

雖然 sns.regplot() 可以顯示線性迴歸趨勢線,但它不會把截距與斜率提供為變數,也無法讓你把模型結果當成變數來操作。這代表有時候你需要自己執行線性迴歸。

現在就來跑你的第一個模型吧!

taiwan_real_estate 已可使用。TWD 是新臺幣的縮寫。

此外,在本練習與本課程後續內容中,會匯入並在需要時設定別名的套件包括:matplotlib.pyplot 作為 pltseaborn 作為 sns,以及 pandas 作為 pd

本練習屬於課程

使用 Python 中的 statsmodels 進行回歸入門

檢視課程

動手互動練習

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

# Import the ols function
from ____ import ____

# Create the model object
mdl_price_vs_conv = ____(____, data=____)

# Fit the model
mdl_price_vs_conv = ____.____

# Print the parameters of the fitted model
print(____.____)
編輯並執行程式碼