Seaborn本身并不是为了统计分析而生的,seaborn中的回归图主要用于添加视觉指南,以帮助在探索性数据分析EDA中强调存在于数据集的模式。
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
sns.set(style='whitegrid', color_codes=True)
plt.rc(
"figure",
autolayout=True,
figsize=(6, 5),
titlesize=18,
titleweight='bold',
)
plt.rc(
"axes",
labelweight="bold",
labelsize="large",
titleweight="bold",
titlesize=16,
titlepad=10,
)
%config InlineBackend.figure_format = 'retina'
warnings.filterwarnings('ignore')
tips = sns.load_dataset('tips',data_home='data',cache=True)
tips.head()
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
绘制线性回归模型的函数
seaborn中主要通过regplot()和lmplot()两个函数来显示线性回归关系,两个函数之间共享核心功能。但是,了解两者的不同之处非常重要,这样就可以快速为特定工作选择正确的工具。
在原始调用中,两个函数都绘制了两个变量x和y,然后拟合回归模型y~x并绘制得到回归线和该回归的95%置信区间:
sns.regplot(x='total_bill', y='tip', data=tips)
<Axes: xlabel='total_bill', ylabel='tip'>

sns.lmplot(x='total_bill', y='tip', data=tips)
<seaborn.axisgrid.FacetGrid at 0x139b79510>

最低0.47元/天 解锁文章
585

被折叠的 条评论
为什么被折叠?



