【问题标题】:Different Q1 and Q3 values in python calculation from TI-nspire来自 TI-nspire 的 python 计算中不同的 Q1 和 Q3 值
【发布时间】:2020-05-13 21:04:55
【问题描述】:

我使用 Numpy/Pandas 和 TI-nspire 计算了上四分位数(Q3 或 75%-tile)和下四分位数(Q1 或 25%-tile)。但我得到不同的价值观。为什么会这样?

从 (5+8)/2=6.5 和 (18+21)/2=19.5,Numpy/Pandas Q1 和 Q3 是错误的。为什么 Numpy/Pandas 会返回错误的数字?

import numpy as np

data=np.array([2,4,5,8,10,11,12,14,17,18,21,22,25])

q75, q25 = np.percentile(data, [75 ,25])
print(q75,q25)


df=pd.DataFrame(data)
df.describe()

Numpy 返回 18.0 和 8.0。 Pandas 返回 18.0 和 8.0。 但 TI-nspire 返回 19.5 和 6.5。

【问题讨论】:

  • 也许可以帮助this

标签: pandas numpy ti-nspire iqr


【解决方案1】:

postpost 帮助我理解了它。

所以如果你有 [7, 15, 36, 39, 40, 41],那么 7 -> 0%, 15 -> 20%, 36 -> 40%, 39 -> 60%, 40 -> 80 %, 41 -> 100%。

interpolation 的默认值是线性的。所以它使用 i + (j - i) * 分数。您可以将插值设置为计算 (i + j) / 2 的中点。

import numpy as np

data=np.array([7,15,36,39,40,41])
linear = np.percentile(data, [25, 50, 75], interpolation='linear')
mid = np.percentile(data, [25, 50, 75], interpolation='midpoint')
low = np.percentile(data, [25, 50, 75], interpolation='lower')
high = np.percentile(data, [25, 50, 75], interpolation='higher')
nearest = np.percentile(data, [25, 50, 75], interpolation='nearest')
print(linear,mid,low,high,nearest)
print(15,37.5,40)

输出:

所以我发现你在 Pandas/Numpy 中找到 Q1 和 Q3 作为 TI-nspire 并没有确切的方法。

【讨论】:

    【解决方案2】:

    您可以请客了。他们都是对的。

    与大多数其他描述符不同,Q1 和 Q3 有几种不同的定义。对于具有大量观察的数据集,不同的定义将给出或多或少相同的结果。对于小型数据集,您会看到差异 - 正如您所经历的那样。

    Mathword 列出了 5 种(五种!)计算四分位数的不同方法。 见http://mathworld.wolfram.com/Quartile.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      相关资源
      最近更新 更多