人工知能数学12週目


人工知能数学:統計学
ジョブ12(ハードウェア12)
  • Python 3コードを作成し、次の操作を行います.
  • は平均5人(λ=1/5\lambda=1/5λ=1/5)指数分布(Exponential Distribution)から7個の乱数を生成して平均値を算出し、このプロセスを実行して20000回算出した20000個の平均値に対して[0,15][0,15]区間全体を0.2単位に分割してヒストグラムを描画する.
  • import numpy as np
    import matplotlib as plt
    n=7
    xbars =[np.mean (np.random.exponential (scale=5,size=n)) for i in range(20000)]
    print("mean %f, var %f" %( np.mean (xbars),np.var(xbars)))
    h= plt.pyplot.hist(xbars, range=(0,15), bins=75)
    
    #mean 4.993251, var 3.487749
    import numpy as np
    import matplotlib as plt
    trial, lam, n = 20000, 1/5, 7
    s, e = 0, 15
    bins = int((e-s)/0.2)
    
    l = [np.mean(np.random.exponential(scale=1/lam, size=n)) for i in range(trial)]
    plt.pyplot.hist(x=l, bins=bins, range=(s, e))
    
    #(array([  0.,   0.,   0.,   1.,  12.,  22.,  52.,  77., 135., 214., 248.,
    #        354., 407., 563., 643., 649., 729., 783., 843., 903., 923., 899.,
    #        894., 874., 824., 834., 799., 749., 729., 652., 577., 490., 457.,
    #        426., 422., 374., 295., 299., 230., 213., 183., 169., 164., 130.,
    #        103., 101.,  79.,  70.,  58.,  48.,  37.,  45.,  40.,  37.,  23.,
    #         16.,  22.,  13.,  12.,   7.,  11.,   5.,   6.,   6.,   3.,   1.,
    #          5.,   3.,   2.,   2.,   0.,   0.,   0.,   1.,   0.]),
    # array([ 0. ,  0.2,  0.4,  0.6,  0.8,  1. ,  1.2,  1.4,  1.6,  1.8,  2. ,
    #         2.2,  2.4,  2.6,  2.8,  3. ,  3.2,  3.4,  3.6,  3.8,  4. ,  4.2,
    #         4.4,  4.6,  4.8,  5. ,  5.2,  5.4,  5.6,  5.8,  6. ,  6.2,  6.4,
    #         6.6,  6.8,  7. ,  7.2,  7.4,  7.6,  7.8,  8. ,  8.2,  8.4,  8.6,
    #         8.8,  9. ,  9.2,  9.4,  9.6,  9.8, 10. , 10.2, 10.4, 10.6, 10.8,
    #        11. , 11.2, 11.4, 11.6, 11.8, 12. , 12.2, 12.4, 12.6, 12.8, 13. ,
    #        13.2, 13.4, 13.6, 13.8, 14. , 14.2, 14.4, 14.6, 14.8, 15. ]),