zoukankan      html  css  js  c++  java
  • 均值,方差: 概率质量函数PMF

    __author__ = 'dell'
    
    import Pmf
    import matplotlib.pyplot as pyplot
    
    
    pmf = Pmf.MakePmfFromList([1, 2, 2, 3, 5])
    print 'Mean by Pmf ', pmf.Mean()
    print 'Var by Pmf ', pmf.Var()
    
    
    def PmfMean(pmf):
        t = [x * v for x, v in pmf.Items()]
        res = sum(t)
        return res
    
    
    def PmfVar(pmf):
        mu = PmfMean(pmf)
        t = [p * ((v - mu) ** 2) for v, p in pmf.Items()]
        res = sum(t)
        return res
    
    print 'Mean by local ', PmfMean(pmf)
    print 'Var by local ', PmfVar(pmf)

    运行结果:
    D:Python27python.exe F:/sync_code/python/survivalanalysis.py
    Mean by Pmf  2.6
    Var by Pmf  1.84
    Mean by local  2.6
    Var by local  1.84
  • 相关阅读:
    8月18号心得
    题解
    考试题
    1055心得
    1055解
    1055题
    心得
    考试三道题
    2017.8.1 居然是倒数第二天了……
    1055
  • 原文地址:https://www.cnblogs.com/i80386/p/3238948.html
Copyright © 2011-2022 走看看