• 概率质量函数:怀孕周期的PMF


    __author__ = 'dell'

    import survey
    import Pmf
    import matplotlib.pyplot as pyplot

    table = survey.Pregnancies()
    table.ReadRecords()
    print "Number of pregnancies ", len(table.records)

    firsts = survey.Pregnancies()
    others = survey.Pregnancies()

    for p in table.records:
        if p.outcome != 1:
            continue
        if p.birthord == 1:
            firsts.AddRecord(p)
        else:
            others.AddRecord(p)

    print 'Num of the first babies :', len(firsts)
    print 'Num of others :', len(others)

    firsts.length = [r.prglength for r in firsts.records]
    others.length = [r.prglength for r in others.records]

    firsts.hist = Pmf.MakeHistFromList(firsts.length, 'firsts')
    others.hist = Pmf.MakeHistFromList(others.length, 'others')

    hists = [firsts.hist, others.hist]

    width = 0.4
    shifts = [-width, 0.0]

    option_list = [dict(color='0.9'), dict(color='blue')]
    pyplot.clf()


    def Shift(xs, shift):
        return [x + shift for x in xs]

    for i, hist in enumerate(hists):
            xs, fs = hist.Render()
            xs = Shift(xs, shifts[i])
            pyplot.bar(xs, fs, label=hist.name, width=width, **option_list[i])

    pyplot.show()

    运行结果:

  • 相关阅读:
    C# 常用函数和方法集
    CSS选择器、优先级和匹配原理
    都是王安石惹的祸?
    世界上的一类
    历史之不可理喻片段
    历史惊人的相似
    20世纪鲜为人知的军事巨灾
    unity制作简单血条
    Unity中Instantiate物体失效问题
    Unity3D实现DoubleClick的一种方法
  • 原文地址:https://www.cnblogs.com/i80386/p/3240993.html
Copyright © 2020-2023  润新知