找到超过特定阈值的概率

finding the probability of exceeding certain threshold

我有一个长度为 324 的数组。我试图根据数组中的值找出超过某个阈值的概率

我试过了::

data = [3,4, 5, 1, 5, 8, 9] ## sample

p = 100 * (4/(len(data)+1)) ## where 4 is my threshold. 

我不确定这是否正确,是否有更好的方法?

如果您将其基于未知的数据分布,则可以采用超出阈值的元素与元素总数之间的比率。由于您已标记 numpy,这里有一个使用它的解决方案。

import numpy as np

data = [3, 4, 5, 1, 5, 8, 9]
data = np.array(data)
threshold = 4
np.sum(data > threshold) / data.size

输出

0.5714285714285714