python - 了解 numpy 百分位计算

标签 python numpy statistics ranking percentile

我在测试分数的背景下理解百分位数,有很多例子(例如,你的 SAT 成绩落在第 99 个百分位数),但我不确定我在以下背景下理解百分位数以及发生了什么。想象一个模型输出概率(有时我们有很多新数据和输出概率,有时则没有)。假设我想计算输出概率的第 99 个百分位。以下是今天的概率:

a = np.array([0,0.2,0.4,0.7,1])
p = np.percentile(a,99)
print(p)

0.988

我不明白在这种只有 5 个输出概率的情况下如何计算第 99 个百分位数。输出是如何计算的?谢谢!

最佳答案

应用线性插值。您可以自己检查一致性:

a = np.array([0,0.2,0.4,0.7,1])

np.sort(a)  # array([ 0. ,  0.2,  0.4,  0.7,  1. ])

np.percentile(a, 75)   # 0.70
np.percentile(a, 100)  # 1.0
np.percentile(a, 99)   # 0.988

0.70 + (1.0 - 0.70) * (99 - 75) / (100 - 75)  # 0.988

文档还specifies 'linear' as the default :

numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)

'linear': i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.

关于python - 了解 numpy 百分位计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54186754/

相关文章:

python - 我在线性时间内合并两个排序列表的实现 - 有什么可以改进的?

python - 如何在抓取时获取html页面中的评论?

python - 用 pandas 数据框中列的最大值和最小值替换 np.inf 和 -np.inf 值?

function - 从高维函数采样

api - Binance API 如何在 24 小时内计算 priceChangePercent

r - 使用 ggplot2 的多面 qqplots

python - 使用整数值的 numpy 数组时处理字符串值

python - imghdr/python - 无法检测某些图像的类型(图像扩展)

python - 如何在 VS Code 中启用 pyspark 和 numpy 的方法建议?

python - Cython对代码的优化