gpt4 book ai didi

python - np.quantile 计算错误?

转载 作者:太空宇宙 更新时间:2023-11-04 02:01:59 24 4
gpt4 key购买 nike

在某些设置下,np.quantile 在确定正确的分位数时会出错。这是错误吗?

x = np.array([374, 358, 341, 355, 342, 334, 353, 346, 355, 344,
349, 330, 352, 328, 336, 359, 361, 345, 324, 386,
334, 370, 349, 327, 342, 354, 361, 354, 377, 324])

q = np.quantile(x, 0.25)

print(q)

print(len(x[x<=q]) / len(x))

print(len(x[x>=q]) / len(x))

输出:

337.25

0.26666666666666666

0.7333333333333333

0.73 表示只有 73% 的值大于或等于确定的分位数;根据定义,它应该是 >= 75%

最佳答案

https://github.com/numpy/numpy/blob/v1.15.1/numpy/lib/function_base.py#L3543-L3644

default value is linear
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
This optional parameter specifies the interpolation method to
use when the desired quantile lies between two data points
``i < j``:
* linear: ``i + (j - i) * fraction``, where ``fraction``
is the fractional part of the index surrounded by ``i``
and ``j``.
* lower: ``i``.
* higher: ``j``.
* nearest: ``i`` or ``j``, whichever is nearest.
* midpoint: ``(i + j) / 2``.

如果你选择“更高”,你会得到你想要的

关于python - np.quantile 计算错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55518198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com