5.Seaborn数据分析

Seaborn数据分析

披萨店顾客数据,图形化分析

import seaborn as sns
# 内置数据集
tips=sns.load_dataset('tips')
tips.tail()
total_billtipsexsmokerdaytimesize
23929.035.92MaleNoSatDinner3
24027.182.00FemaleYesSatDinner2
24122.672.00MaleYesSatDinner2
24217.821.75MaleNoSatDinner2
24318.783.00FemaleNoThurDinner2

带状图

离散数据 和 连续数据 之间的关系

sns.stripplot(x='day', y='total_bill', data=tips, jitter=False)
<matplotlib.axes._subplots.AxesSubplot at 0x11a775400>

在这里插入图片描述

#jitter 抖动
sns.stripplot(x='day', y='total_bill', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11cf48cf8>

在这里插入图片描述

蜂群图

离散数据 和 连续数据 之间的关系——密度排列

带状图的补充

不允许在一起

sns.swarmplot(x='day', y='total_bill', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11cf5c6d8>

在这里插入图片描述

tips.head()
total_billtipsexsmokerdaytimesize
016.991.01FemaleNoSunDinner2
110.341.66MaleNoSunDinner3
221.013.50MaleNoSunDinner3
323.683.31MaleNoSunDinner2
424.593.61FemaleNoSunDinner4

3.Hue-分组参数

分析每天中,午餐和晚餐的账单分布

周六 都是晚上吃饭?晚上去放松

sns.swarmplot(x='day', y='total_bill', data=tips, hue='time')
<matplotlib.axes._subplots.AxesSubplot at 0x11a95f198>

在这里插入图片描述

每天的付账人群中的性别分布

sns.swarmplot(x='day', y='total_bill', data=tips, hue='sex')
<matplotlib.axes._subplots.AxesSubplot at 0x11a934b70>

在这里插入图片描述

sns.swarmplot(x='day', y='total_bill', data=tips, hue='size')
<matplotlib.axes._subplots.AxesSubplot at 0x11d4b4f98>

在这里插入图片描述

sns.swarmplot(data=tips, x='size', y='total_bill')
<matplotlib.axes._subplots.AxesSubplot at 0x11a86fda0>

在这里插入图片描述

pizza的不同size的基础价格

tips['size'].corr(tips['total_bill'])
0.59831513090490129

箱线图

中位数、1/4位点、3/4位点、min、max、离散点分布

高斯分布,基本包括96%

之外的是离群点,小概率,分布不规律

表示total_bill的概率分布

sns.boxplot('day', 'total_bill',data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11a84e898>

在这里插入图片描述

sns.swarmplot('day', 'total_bill', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11a630eb8>

在这里插入图片描述

sns.boxplot('day', 'total_bill', data=tips, hue='time')
<matplotlib.axes._subplots.AxesSubplot at 0x10b8c3710>

在这里插入图片描述

提琴图

对称, 概率密度

把正态分布画出来

# 忽略警告信息
import warnings
warnings.filterwarnings("ignore")
sns.violinplot('day', 'total_bill', data=tips, hue='time')
<matplotlib.axes._subplots.AxesSubplot at 0x11d9e9940>

在这里插入图片描述

# 只需看1半
sns.violinplot('day', 'total_bill', data=tips, hue='time', split=True)
<matplotlib.axes._subplots.AxesSubplot at 0x10a940cf8>

在这里插入图片描述

多图展示

花朵里的种子

sns.violinplot('day', 'total_bill', data=tips)
sns.swarmplot('day', 'total_bill', data=tips, color='white')
<matplotlib.axes._subplots.AxesSubplot at 0x11e84dbe0>

在这里插入图片描述

单一变量估计

多与少,频度、每天交易数量

离散型数据的频次统计

sns.countplot('day', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x1132268d0>

在这里插入图片描述

sns.countplot('time', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11df9a4e0>

在这里插入图片描述

sns.countplot('day', data=tips, hue='time')
<matplotlib.axes._subplots.AxesSubplot at 0x11de00940>

在这里插入图片描述

sns.countplot('size', data=tips)
<matplotlib.axes._subplots.AxesSubplot at 0x11dec4f98>

在这里插入图片描述

连续型数据的核密度估计

tips.head()
total_billtipsexsmokerdaytimesize
016.991.01FemaleNoSunDinner2
110.341.66MaleNoSunDinner3
221.013.50MaleNoSunDinner3
323.683.31MaleNoSunDinner2
424.593.61FemaleNoSunDinner4
sns.distplot(tips['total_bill'])
<matplotlib.axes._subplots.AxesSubplot at 0x113564dd8>

在这里插入图片描述

抵消偏度

拉成比较偏正态的函数?

小技巧,不要太多使用!可以尝试

降阶取log,只描述宏观场景,微观细节给抵消了

import numpy as np
sns.distplot(np.log(tips['total_bill']))
<matplotlib.axes._subplots.AxesSubplot at 0x11e0e5c50>

在这里插入图片描述

抽取前 99.5%的数据(去掉离散值的方法)

2 σ \sigma σ

np.percentile(tips['total_bill'], 99.5)
48.317099999999996
# 离群点,可将其去掉
tips[tips['total_bill']>48.31]
total_billtipsexsmokerdaytimesize
17050.8110.0MaleYesSatDinner3
21248.339.0MaleNoSatDinner4

带回归的散点图

看相关性

sns.lmplot('size', 'total_bill', data=tips)
<seaborn.axisgrid.FacetGrid at 0x11e900c50>

在这里插入图片描述

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

在这里插入图片描述

联合分布(既有散点的特性,又有线性回归,同时还有概率估计)

基本呈正态分布

自然存在的东西,基本都属于正态分布

每天花销,购物量,记记账

sns.jointplot('total_bill', 'tip', data=tips, kind='reg')
<seaborn.axisgrid.JointGrid at 0x11ea30c50>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值