三、分类分布图
目录
1.boxplot()
它的作用是可以直观的查看异常值
seaborn.boxplot(x=None, y=None, hue=None, data=None, order=None,
hue_order=None, orient=None, color=None, palette=None, saturation=0.75,
width=0.8, dodge=True, fliersize=5, linewidth=None, whis=1.5, notch=False, ax=None, **kwargs)
一些参数已经在前两篇文章中进行了详细描述。如果您需要查看参数说明,请跳转。
[En]
Some of the parameters have been described in detail in the previous two articles. If you need to check the parameter explanation, please jump.
部分参数解释如下:
- saturation:饱和度,可设置为1;
- width:float,控制箱型图的宽度大小;
- fliersize:float,用于指示离群值观察的标记大小;
- whis:可理解为异常值的上限IQR比例;
sns.set_style('darkgrid')
sns.boxplot(x="day", y='total_bill', data=tips)
从上图可以看出,顶部的菱形图案是异常值,中间的水平线是中值,盒子的上、下四分位数分别是上、下四分位数。
[En]
From the picture above, we can see that the diamond pattern at the top is an outlier, the horizontal line in the middle is the median, and the upper and lower quartiles of the box are respectively the upper and lower quartiles.
sns.boxplot(x="day", y='total_bill', hue='smoker', data=tips)
sns.boxplot(x="day", y='total_bill', data=tips, fliersize=10)
sns.swarmplot(x='day', y='total_bill', data=tips)
将分swarmplot和boxplot结合起来可以清晰的看出数据的分布情况
2.violinplot
小提琴图的功能与箱型图类似。 它显示了一个(或多个)分类变量多个属性上的定量数据的分布,从而可以比较这些分布。与箱形图不同,其中所有绘图单元都与实际数据点对应,小提琴图描述了基础数据分布的核密度估计。小提琴图可以是一种单次显示多个数据分布的有效且有吸引力的方式,但请记住,估计过程受样本大小的影响,相对较小样本的小提琴可能看起来非常平滑,这种平滑具有误导性。
seaborn.violinplot(x=None, y=None, hue=None, data=None, order=None,
hue_order=None, bw='scott', cut=2, scale='area', scale_hue=True, gridsize=100,
width=0.8, inner='box', split=False, dodge=True, orient=None, linewidth=None,
color=None, palette=None, saturation=0.75, ax=None, **kwargs)
注:小提琴图的特点是估计基本分布的核密度。通过小提琴的绘画,我们可以知道哪里的密度较高。在图片中,白点为中值,黑框从下四分位数到上四分位数,细黑线表示四分位数。外部形状是核密度的估计。
[En]
Note: the violin drawing is characterized by the estimation of the kernel density of the basic distribution. Through the violin drawing, we can know where the density is higher. In the picture, the white dot is the median, the black box ranges from the lower quartile to the upper quartile, and the thin black line indicates the quartile. The external shape is the kernel density estimation.
参数解析:
- bw:'scott', 'silverman', float,控制拟合程度。在计算内核带宽时,可以引用规则的名称('scott', 'silverman')或者使用比例(float)。实际内核大小将通过将比例乘以每个bin内数据的标准差来确定;
- cut:空值外壳的延伸超过极值点的密度,float;
- scale:"area", "count", "width",用来缩放每把小提琴的宽度的方法;
- scale_hue:当使用hue分类后,设置为True时,此参数确定是否在主分组变量进行缩放;
- gridsize:设置小提琴图的平滑度,越高越平滑;
- inner:"box", "quartile", "point", "stick", None,小提琴内部数据点的表示。分别表示:箱子,四分位,点,数据线和不表示;
- split:是否拆分,当设置为True时,绘制经hue分类的每个级别画出一半的小提琴;
sns.violinplot(x="day", y="total_bill", data=tips)
图中的轮廓为核密度估计,中间白点为中位数。其他通发同上
四、分类估计图
1.barplot()
seaborn.barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None,
estimator=, ci=95, n_boot=1000, units=None, orient=None,
color=None, palette=None, saturation=0.75, errcolor='.26', errwidth=None,
capsize=None, dodge=True, ax=None, **kwargs)
条形图表示数值变量中心趋势的估计值和每个矩形的高度,用矩形条形图表示点估计和可信区间,并使用误差线提供估计值附近的不确定性的某种指示。
[En]
The bar chart represents the estimated value of the central trend of the numerical variable and the height of each rectangle, represents the point estimate and confidence interval with a rectangular bar, and uses error lines to provide some indication of the uncertainty near the estimated value.
参数如下:
-
estimator:用于估计每个分类箱内的统计函数,默认为mean。当然你也可以设置estimator=np.median/np.std/np.var......
-
order:选择和空值顺序,例如:order=['Sat','Sun'];
- ci:允许的误差的范围(控制误差棒的百分比,在0-100之间),若填写"sd",则用标准误差(默认为95),也可设置ci=None;
- capsize:设置误差棒帽条(上下两根横线)的宽度,float;
- saturation:饱和度;
- errcolor:表示置信区间的线条的颜色;
- errwidth:float,设置误差条线(和帽)的厚度。
sns.barplot(x='day', y='total_bill', data=tips)
没有绘制误差棒帽条的宽度,看起来还是很丑的。
sns.barplot(x='day', y='total_bill', data=tips, errwidth=4, capsize=0.2, hue='sex')
2.countplot()
对输入的单个变量的数据进行计数
seaborn.countplot(x=None, y=None, hue=None, data=None, order=None,
hue_order=None, orient=None, color=None, palette=None, saturation=0.75,
dodge=True, ax=None, **kwargs)
sns.countplot(x='day', data=tips)
可以理解为对数据中的特征进行计数
sns.countplot(x='day', data=tips, dodge=True, hue='sex')
按照hue='sex'分类之后计数,得到上图。
3.pointplot()
用散点图符号表示点估计和置信区间,点图代表散点图位置的数值变量的中心趋势估计,并使用误差线提供关于该估计的不确定性的一些指示。点图可能比条形图(barplot)更有用于聚焦一个或多个分类变量的不同级别之间的比较。他们尤其善于表现交互作用:一个分类变量的层次之间的关系如何在第二个分类变量的层次之间变化。连接来自相同色调等级的每个点的线允许交互作用通过斜率的差异进行判断,这比对几组点或条的高度比较容易。
seaborn.pointplot(x=None, y=None, hue=None, data=None, order=None,
hue_order=None, estimator=, ci=95, n_boot=1000,
units=None, markers='o', linestyles='-', dodge=False, join=True,
scale=1, orient=None, color=None, palette=None, errwidth=None,
capsize=None, ax=None, **kwargs)
- join:默认两个均值点会相连接,若不想显示,可以通过join=False参数实现;
- scale:float,均值点(默认)和连线的大小和粗细。
sns.pointplot(y='day', x='total_bill', data=tips)
五、多变量绘图函数
1.joinplot()
joint意为联合,顾名思义jointplot是一个双变量分布图表接口。绘图结果主要有三部分:绘图主体用于表达两个变量对应的散点图分布,在其上侧和右侧分别体现2个变量的直方图分布
seaborn.jointplot(x,y,data=None,kind='scatter',stat_func=None,color=None,height=6
,ratio=5,space=0.2,dropna=True,xlim=None,ylim=None,joint_kws=None,marginal_kws=None,
annot_kws=None,**kwargs)
x,y:data中的数据或变量名,strings或vectors
data:DataFrame,
kind:默认为scatter,还有reg,resid,kde,hex
color:颜色
height:图像尺寸
ratio:中心轴的高度与侧边轴高度的比例, 即hist图的高度
space:中心和侧边轴的间隔大小,如下图示,为坐标轴边界与直方图的距离
dropna:bool,如果为True,移除xy中的缺失值
xlim、ylim:x、y轴范围
sns.jointplot(x='total_bill', y='tip', data=tips, kind='reg')
sns.jointplot(x='total_bill', y='tip', data=tips, kind='reg', ratio=5, space=2)
设置ratio后,直方图的高度会发生变化,设置space后直方图与点图之间的距离会发生变化。
2.pairplot()
此函数用于变量数目大于两个的情况;它将任何函数组合成一个子图,其中对角线作为直方图,其他函数作为散点图。
[En]
This function is used when the number of variables is greater than two; it combines any function into a subgraph, with diagonals as histograms and others as scatter plots.
seaborn.pairplot(data,hue=None,hue_order=None,palette=None,vars=None,x_vars=None,
y_vars=None,kind='scatter',diag_kind='auto',markers=None,height=2.5,aspect=1,
dropna=True,plot_kws=None,diag_kws=None,grid_kws=None,size=None)
data:数据框架每列是变量,每行是观察量
hue:str,data中的变量将绘图方面映射到不同的颜色(列名, 即特征)
hue_order:list[str],命令调色板中的色调变量的级别
palette:字典或者seaborn调色板。用于映射hue变量的颜色集。如果是字典,关键字应该是hue变量中的值
markers:设置点的样式, 列表表示
diag_kind:对角线子图的类型,可选auto,kde,hist
(x,y)_vars:变量名列表,用于绘制指定x,y的图形
iris = pd.read_csv('iris.csv')
sns.pairplot(iris)
我们可以清楚的看到各个变量之间的相互关系
sns.pairplot(iris, hue='species')
还有两个非常有用的参数x_vars和y_vars,那具体是怎么使用的呢?
sns.pairplot(iris, x_vars=['sepal_width', 'sepal_length'], y_vars=['sepal_width', 'sepal_length'])
我们可以得出结论:x_vars和y_vars可以指定变量绘制我们想要的图形。
Original: https://blog.csdn.net/gswsssw/article/details/122930096
Author: xz---
Title: 数据可视化——seaborn(三)
相关阅读
Title: dirsearch安装+使用+运行问题(小宇特详解)
dirsearch安装+使用+运行问题(小宇特详解)
前几天电脑坏了重新安装了一下dirsearch,却发现好多问题今天写个文章说一下
这里着重说一下我运行时出现的问题
安装
dirsearch是一个用python开发的网站目录扫描工具
github下载地址
我的系统是win10的
我一开始是将这个东西放到过D盘,也放到过python3环境的位置进行了解压
这里两个方式都可
一般解压之后就可以使用
; 使用
使用的方法就是打开dirsearch-master文件后打开cmd命令
打开后运行
python setup.py
安装后运行
python dirsearch.py -u ip
详细用法可以查看帮助
python dirsearch.py -h
运行问题
这里我详细说一下这个问题
首先是缺库问题
这里请看图
解决办法
pip install certifi
后来又出现了
这时用上面的方法来pip的话,我这里出现了问题
这里提示pip版本过低
这里升级pip
这里先查看pip版本
pip -V
然后直接升级pip
D:\python3\python.exe -m pip install --upgrade pip
这里的D:\python3\python.exe是我电脑上的python路径
然后
pip install cryptography
这里又出现问题了
这个问题我找了半天才找到原因。
这里提示连接被中断,一开始没多想觉得时pip被国内的网断了觉得时下面红字提示的找不到满足加密要求的版本的问题
后来我关了我电脑上的代理才解决了问题。这里直接关代理运行上面的pip即可。
希望我走过的坑你们不用再走。
Original: https://blog.csdn.net/xhy18634297976/article/details/122900500
Author: 小宇特详解
Title: dirsearch安装+使用+运行问题(小宇特详解)

【语音算法】wav2vec系列原理和使用

在Windows使用miniconda安装Tensorflow-GPU版,无需去Nvidia官网下载安装cuda和cudnn

Pytorch实战_图像降维及聚类

pandas.DataFrame.fillna

iOS 缓存框架YYCache学习

OCR文字识别技术总结(三)

安装tensorflow教程(自用)

【蓝牙Mesh笔记 ①】ESP32-C3 模组上实现天猫精灵蓝牙 BLE Mesh AliGenie 接入,无需WiFi 连接也可以实现天猫精灵语音控制。

MFCC声纹特征提取

三、以用户为中心的数据驱动产品设计

A listener indicated an asynchronous response by returning true

keras搭建unet模型—语义分割

jovi语音助手安装包_jovi语音助手下载

pytorch使用transformers库进行fine-tuning微调
