迴歸圖

Seaborn 資料視覺化中級

Chris Moffitt

Instructor

自行車資料集

  • 華盛頓特區的自行車共享彙整資料
  • 資料包含:
    • 租借量
    • 天氣資訊
    • 行事曆資訊
  • 我們能預測租借量嗎?
Seaborn 資料視覺化中級

使用 regplot() 繪圖

sns.regplot(data=df, x='temp', 
            y='total_rentals', marker='+')

迴歸圖

Seaborn 資料視覺化中級

用 residplot() 評估迴歸

  • 殘差圖可用來評估模型擬合
  • Seaborn 透過 residplot 提供支援
sns.residplot(data=df, x='temp', y='total_rentals')

殘差圖

Seaborn 資料視覺化中級

多項式迴歸

  • Seaborn 透過 order 參數支援多項式迴歸
sns.regplot(data=df, x='temp', 
            y='total_rentals', order=2)

迴歸圖

Seaborn 資料視覺化中級

多項式迴歸下的 residplot

sns.residplot(data=df, x='temp', 
              y='total_rentals', order=2)

殘差圖

Seaborn 資料視覺化中級

類別型數值

sns.regplot(data=df, x='mnth', y='total_rentals',
            x_jitter=.1, order=2)

殘差圖

Seaborn 資料視覺化中級

估計量

  • 在某些情況,x_estimator 有助於凸顯趨勢
sns.regplot(data=df, x='mnth', y='total_rentals',
            x_estimator=np.mean, order=2)

殘差圖

Seaborn 資料視覺化中級

資料分箱

  • 可用 x_bins 將資料切成數個離散箱
  • 迴歸線仍對所有資料擬合
sns.regplot(data=df,x='temp',y='total_rentals',
            x_bins=4)

殘差圖

Seaborn 資料視覺化中級

一起來練習吧!

Seaborn 資料視覺化中級

Preparing Video For Download...