Seaborn箱线图四分位数计算 [英] Seaborn boxplot quartile calculation

查看:62
本文介绍了Seaborn箱线图四分位数计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中使用 seaborn 0.7.1 版.我正在尝试为下面的 numpy 数组创建一个箱线图

i am using seaborn version 0.7.1 for python. I am trying to create a boxplot for the below numpy array

arr = np.array([2, 4, 5, 5, 8, 8, 9])

根据我的理解,四分位数 Q1 和 Q3 应该是 4 和 8,但从生成的箱线图中,Q1 约为 4.5.我错过了什么?

from my understanding the Quartiles Q1 and Q3 should be 4 and 8 but from the boxplot generated the Q1 is approximately 4.5. What am i missing ?

我正在使用以下命令生成图表

i am using the follwing command to generate the chart

sns.boxplot(arr)

推荐答案

这当然取决于四分位数的定义.

It would of course depend on the definition of a quartile.

维基百科 提到了 3 种计算四分位数的方法,

Wikipedia mentions 3 methods to calculate the quartile,

  • method1:取样本下部的中位数[2,4,5].结果 4.
  • method2:取样本下部的中位数(包括其中位数)[2,4,5,5].结果 4.5.
  • method3:下四分位数是第二个数据值的 75% 加上第三个数据值的 25%.结果:4*0.75+5*0.25 = 4.25.(它始终是方法 1 和方法 2 之间的平均值.

您也可以使用 numpy 来计算四分位数

You may also use numpy to calculate the quartiles

x = [2, 4, 5, 5, 8, 8, 9]
np.percentile(x, [25])

这将返回 4.5

这篇关于Seaborn箱线图四分位数计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆