Fitting a histogram with python

后端 未结 5 1289
梦毁少年i
梦毁少年i 2020-11-28 02:18

I have a histogram

H=hist(my_data,bins=my_bin,histtype=\'step\',color=\'r\')

I can see that the shape is almost gaussian but I would like t

5条回答
  •  猫巷女王i
    2020-11-28 02:50

    Starting Python 3.8, the standard library provides the NormalDist object as part of the statistics module.

    The NormalDist object can be built from a set of data with the NormalDist.from_samples method and provides access to its mean (NormalDist.mean) and standard deviation (NormalDist.stdev):

    from statistics import NormalDist
    
    # data = [0.7237248252340628, 0.6402731706462489, -1.0616113628912391, -1.7796451823371144, -0.1475852030122049, 0.5617952240065559, -0.6371760932160501, -0.7257277223562687, 1.699633029946764, 0.2155375969350495, -0.33371076371293323, 0.1905125348631894, -0.8175477853425216, -1.7549449090704003, -0.512427115804309, 0.9720486316086447, 0.6248742504909869, 0.7450655841312533, -0.1451632129830228, -1.0252663611514108]
    norm = NormalDist.from_samples(data)
    # NormalDist(mu=-0.12836704320073597, sigma=0.9240861018557649)
    norm.mean
    # -0.12836704320073597
    norm.stdev
    # 0.9240861018557649
    

提交回复
热议问题