回归图

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 数据可视化进阶

Passons à la pratique !

Seaborn 数据可视化进阶

Preparing Video For Download...