确定超过特定阈值的可能性

问题描述 投票:0回答:1

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

我已经尝试过::

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

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

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

python probability
1个回答
2
投票

如果您基于未知的数据分布,则可以采用超出阈值的元素与元素总数之间的比率。由于您已标记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
© www.soinside.com 2019 - 2024. All rights reserved.