繪製資料與線性模型擬合
在前面的練習中,你已經練習如何擬合並解讀 Poisson 迴歸模型。這個練習中,你會先以視覺化方式檢視 crab 資料,接著檢視模型擬合。
首先,你會對資料繪出一個「線性」擬合,之後再用它來和 Poisson 迴歸的擬合值比較。
本練習屬於課程
Generalized Linear Models in Python
練習說明
- 匯入
seaborn與matplotlib函式庫。 - 使用
crab資料集繪出資料點:x 軸為width、y 軸為sat,並對sat變數加入0.3的抖動(jitter)。 - 透過將參數
fit_reg設為True來加入線性模型擬合。 - 將擬合線的
'color'設為'green',並將'label'設為'LM fit'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import libraries
import ____ as sns
import ____.pyplot as plt
# Plot the data points and linear model fit
sns.regplot(____, ____, data = ____,
y_jitter = ____,
fit_reg = ____,
line_kws = {'color':____,
'label':____})
# Print plot
plt.show()