Search code examples
pythonprobability

finding the probability of exceeding certain threshold


I have an array of lenghth 324. I am trying to find the probability of exceeding certain threshold based on the values in the array

I have tried::

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

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

I am not sure if this is right and is there a better way of doing this?


Solution

  • If you're basing this on an unknown distribution of data, you can take the ratio between the elements that exceed your threshold and the total number of elements. Since you've tagged numpy, here is a solution that uses it.

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

    Output

    0.5714285714285714