開始使用免費開始

繪製資料與線性模型擬合

在前面的練習中,你已經練習如何擬合並解讀 Poisson 迴歸模型。這個練習中,你會先以視覺化方式檢視 crab 資料,接著檢視模型擬合。

首先,你會對資料繪出一個「線性」擬合,之後再用它來和 Poisson 迴歸的擬合值比較。

本練習屬於課程

Generalized Linear Models in Python

檢視課程

練習說明

  • 匯入 seabornmatplotlib 函式庫。
  • 使用 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()
編輯並執行程式碼