i80386

均值,方差: 概率质量函数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:\Python27\python.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

 

分类:

技术点:

相关文章:

  • 2022-01-03
  • 2021-12-19
  • 2022-02-09
  • 2022-02-10
  • 2022-02-23
  • 2022-02-07
  • 2022-02-18
猜你喜欢
  • 2021-12-04
  • 2021-11-29
  • 2022-02-10
  • 2022-01-01
  • 2021-12-31
  • 2021-12-02
  • 2021-12-19
相关资源
相似解决方案