当使用Python Numpy计算分位数/百分位数时,结果有点奇怪,如下所示。我对此很困惑,有谁能解释一下原因吗?
import numpy as np
x = range(1,1031)
x = np.array(x)
np.percentile(x,1,interpolation='lower')
# 11
np.percentile(x,1,interpolation='higher')
# 12
np.percentile(x,0.972,interpolation='lower')
# 11
np.percentile(x,0.972,interpolation='higher')
# 12
np.percentile(x,0.971,interpolation='lower')
# 10
np.percentile(x,0.971,interpolation='higher')
# 11我期望从1到1030的数字的更低和更高的1%分位数是10和11,但实际结果是11和12。
发布于 2019-06-19 09:28:17
想象一下,您的数组是x = range(1,1002) (即1到1001,包括1到1001)。那么1是0%的百分位数,1001是100%。中位数是501,应该是50%的百分位数。从这个模式中,您可能可以插值得到p%百分位数应该是10p+1,特别是1%百分位数应该是11。
现在,既然您的实际数组是range(1,1031),1%的百分位数不是应该稍微高一点吗?
https://stackoverflow.com/questions/56658831
复制相似问题