Statistical Analysis Python visualization library Seaborn (correlation graph, variable profile, box plot and the like)

Seaborn of the Visualization
  Seaborn [1] is a built on matplot, can be used to create rich and very attractive statistical graphics Python libraries. Seaborn library is designed to visualize data as exploration and understanding of the core part, contribute to help people understand data sets closer study. Whether in kaggle the official website of the game algorithm, or the Internet company's actual business data mining scenario, has its presence.

   In this project this presentation, we will use seaborn library data set for analysis, displaying different types of statistical graphics.

First, we will import all necessary packages required for visualization, we will use several packages:

Numpy
pandas
matplotlib
Seaborn

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

tips = pd.read_csv('tips.csv')
tips.head()

 

 

Each attribute relevance

# Relevance 
tips.corr ()
Out[2]: 
            total_bill       tip      size
total_bill    1.000000  0.675734  0.598315
tip           0.675734  1.000000  0.489299
size          0.598315  0.489299  1.000000

 

pair plot图

#相关性图 很壮观
sns.pairplot(tips) 

看图说话:这些图展现了数据集中消费总额、小费金额以及顾客数量三个特征(变量)之间的联系。

 

#相关性图,和某一列的关系
sns.pairplot(tips ,hue ='sex', markers=["o", "s"])

 

# 相关性热力图
sns.heatmap(tips.corr())

 看图说话:热力图可用来显示两变量之间的相关性,在这里两变量间对应的矩形框的颜色越浅,代表两者之间越具有相关性。

# 分层相关性热力图
sns.clustermap(tips.corr())

 

g = sns.PairGrid(tips)
g.map_diag(sns.distplot)
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)

看图说话:这个厉害了。在pair grid图中,你可以根据自己需求,在这里呈现上述介绍的各种类型的图形。

 

单个属性的分布

 

dist plot图

sns.distplot(tips['total_bill'])

 

 

sns.distplot(tips['total_bill'],kde = False)

看图说话:上图显示,顾客在餐厅的消费总金额主要是在5-35的范围内分布的。

 

count plot图

sns.countplot(x = 'smoker', data = tips)

看图说话:上图显示,来餐厅就餐的顾客,不抽烟者比会抽烟者多

 

sns.countplot(x = 'size',  data = tips)

这里写图片描述 
看图说话:上图显示,2个人来餐厅就餐的总次数多一些。

 

rug plot图

sns.rugplot(tips['total_bill'])

 


看图说话:上图呈现的是,顾客就餐消费总额在各个值上的边缘分布。

 

kde plot图

sns.kdeplot(tips['total_bill'], shade=True)

 

 

看图说话:KDE代表内核密度估计,它也显示了各个消费总金额数值的统计分布。

 

 

两两属性的相关性图

 

joint plot图

sns.jointplot(x = 'total_bill', y = 'tip', data = tips)


看图说话:上图显示,顾客主要消费水平在10-30远之间,而此时,对应给侍者小费的钱在1-5元之间。

 

sns.jointplot(x = 'total_bill', y = 'tip', data = tips ,kind = 'hex')

 

另一种清晰地可视化视图,颜色的深度代表频次。

 

sns.jointplot(x = 'total_bill', y = 'tip', data = tips ,kind = 'reg')

 

 

看图说话:通过做一条简单的回归线,它表明了小费的金额是随着总账单金额的增加而增加的。

 

sns.jointplot(x = 'total_bill', y = 'tip', data = tips ,kind = 'kde')

 

 

另一种可视化统计图:某个区域越暗,表明这个区域对应的频次越多。

 

box plot图

sns.boxplot(x = 'day', y= 'total_bill', data = tips)


看图说话:上图显示大部分账单是在周六和周日支付的。

sns.boxplot(x = 'day', y= 'total_bill', data = tips, hue = 'sex')

 

看图说话:在上面的图表中你可以看到,在周六时,女性买单的次数会比男性多。(难道是因为买买买,男性付了好多钱,女性为了弥补男性的心里落差,然后请吃饭?哈哈)

 

violin plot

sns.violinplot(x = 'day', y= 'total_bill', data = tips)

 

看图说话:voilin plot和box plot很相似,但它结合了box plot图和密度痕迹。

sns.violinplot(x = 'day', y= 'total_bill', data = tips, hue = 'sex', split = True)

 

 

看图说话:增加了性别的区分

 

strip plot图

sns.stripplot(x = 'day', y = 'total_bill', data = tips)

 

 

看图说话:这幅图呈现的是周四、周五、周六和周日这四天,顾客消费总额的散点图。

 

sns.stripplot(x = 'day', y = 'total_bill', data = tips, jitter= True,hue = 'sex', dodge = True)

 

 

看图说话:和上图一样,只不过对性别进行了区别。

 

swarm plot图

sns.swarmplot(x = 'day', y = 'total_bill', data = tips)

 

 

看图说话:Swarn plot和stripplot比较类似,但Swarn plot的不同之处在于它不会重叠数据点。

 

factor plot图

sns.factorplot(x = 'day', y = 'total_bill', kind = 'box', data = tips)

 

 

看图说话:在factorplot图中,你可以给出任何你需要显示的图形。

Guess you like

Origin www.cnblogs.com/caiyishuai/p/11184166.html