pylab.hist(data, normed=1). Normalization seems to work incorrect

后端 未结 7 1279
感情败类
感情败类 2020-12-01 07:40

I\'m trying to create a histogram with argument normed=1

For instance:

import pylab

data = ([1,1,2,3,3,3,3,3,4,5.1])    
pylab.hist(data, normed=1)
         


        
7条回答
  •  [愿得一人]
    2020-12-01 08:08

    Your expectations are wrong

    The sum of the bins height times its width equals to one. Or, as you said correctly, the integral has to be one, not the function you are integrating about.

    It's like this: probability (as in "the probability that the person is between 20 and 40 years old is ...%") is the integral ("from 20 to 40 years old") over the probability density. The bins height shows the probability density whereas the width times height shows the probability (you integrate the constant assumed function, height of bin, from beginning of bin to end of bin) for a certain point to be in this bin. The height itself is the density and not a probability. It is a probability per width which can be higher then one of course.

    Simple example: imagine a probability density function from 0 to 1 that has value 0 from 0 to 0.9. What could the function possibly be between 0.9 and 1? If you integrate over it, try it out. It will be higher then 1.

    Btw: from a rough guess, the sum of height times width of your hist seems to yield roughly 1, doesn't it?

提交回复
热议问题