单变量分析操作

import numpy as np
import pandas as pd
from scipy import stats,integrate
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
np.random.seed(sum(map(ord,"distribution")))
x=np.random.normal(size=100)
sns.distplot(x,kde=True)#kde生成核密度估计

<matplotlib.axes._subplots.AxesSubplot at 0x1f61c2f6cf8>

单变量分析操作

sns.distplot(x,kde=True,bins=20)#bin更具体的分桶操作
<matplotlib.axes._subplots.AxesSubplot at 0x1f61c2f64a8>

单变量分析操作

sns.distplot(x,kde=False,bins=20,rug=20)#使用rug生成实例
<matplotlib.axes._subplots.AxesSubplot at 0x1f61cf39400>

单变量分析操作

#核密度估计
#通过观测估计概率密度函数的形状。 
''''有什么用呢?待定系数法求概率密度函数~
核密度估计的步骤: 
* 每一个观测附近用一个正态分布曲线近似 
* 叠加所有观测的正太分布曲线 
* 归一化
  File "<ipython-input-7-675869d1e240>", line 3
    有什么用呢?待定系数法求概率密度函数~
                     ^
SyntaxError: invalid character in identifier
sns.kdeplot(data=x)
<matplotlib.axes._subplots.AxesSubplot at 0x1f61c8b05c0>

单变量分析操作

sns.kdeplot(x,c="green",shade=True)#核密度估计图
sns.kdeplot(x,bw=.2,label="bw:0.2",c="red")
sns.kdeplot(x,bw=2,label="bw:2",c="purple")
plt.legend()#设置图例位置
D:\ano\lib\site-packages\matplotlib\cbook\__init__.py:2400: UserWarning: Saw kwargs ['c', 'color'] which are all aliases for 'color'.  Kept value from 'color'
  seen=seen, canon=canonical, used=seen[-1]))





<matplotlib.legend.Legend at 0x1f61d0d37f0>

单变量分析操作

#模型参数拟合
x=np.random.gamma(6,size=200)#伽马分布
sns.distplot(x,kde=False,fit=stats.gamma,axlabel="XX",color="red",label="yy")#fit控制拟合的参数分布图形

<matplotlib.axes._subplots.AxesSubplot at 0x1f61e312ba8>

单变量分析操作

#双变量分布
mean,cov=[0,1],[(1,.5),(.5,1)]
data=np.random.multivariate_normal(mean,cov,200)#多元正态分布 multivariate_normal(mean, cov[, size])
df=pd.DataFrame(data,columns=["x","y"])
sns.jointplot(x="x",y="y",data=df)#散点图
<seaborn.axisgrid.JointGrid at 0x1f61e806fd0>

单变量分析操作

x,y=np.random.multivariate_normal(mean,cov,1000).T
with sns.axes_style("ticks"):
    sns.jointplot(x=x,y=y,kind="hex")#hex六角图

单变量分析操作

sns.jointplot(x="x",y="y",data=df,kind="kde")#核密度估计
<seaborn.axisgrid.JointGrid at 0x1f61e93b3c8>

单变量分析操作

f,ax=plt.subplots(figsize=(6,6))
sns.kdeplot(df.x,df.y,ax=ax)#ax?
sns.rugplot(df.x,df.y,color="g",ax=ax)
sns.rugplot(df.y,vertical=True,ax=ax)

单变量分析操作

f,ax=plt.subplots(figsize=(6,6))
cmap=sns.cubehelix_palette(as_cmap=True,dark=1,light=0)#.cubehelix_palette序列颜色
#cmap=True传入颜色映射对象
sns.kdeplot(df.x,df.y,cmap=cmap,n_levels=60,shade=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1f61e68d908>

单变量分析操作