How to compute the probability of a value given a list of samples from a distribution in Python?

后端 未结 3 477
春和景丽
春和景丽 2020-12-12 22:42

Not sure if this belongs in statistics, but I am trying to use Python to achieve this. I essentially just have a list of integers:

data = [300,244,543,1011,3         


        
3条回答
  •  猫巷女王i
    2020-12-12 23:37

    Here is one possible solution. You count the number of occurrences of each value in the original list. The future probability for a given value is its past rate of occurrence, which is simply the # of past occurrences divided by the length of the original list. In Python it's very simple:

    x is the given list of values

    from collections import Counter
    c = Counter(x)
    
    def probability(a):
        # returns the probability of a given number a
        return float(c[a]) / len(x)
    

提交回复
热议问题