Why is probability density funciton equal to 1 between 0 and 1

probability distributions

I think I don't get the probability density function. At least on uniform distribution.

There are infinitely many numbers between $0$ and $1$, in probability, I understand this means that the weight it assigns to individual points must necessarily be zero. For this reason, we represent a continuous distribution with a probability density function (pdf) such that the probability of seeing a value in a certain interval equals the integral of the density function over the interval.

Then I don't get why, in this book page 74, the density function for the uniform distribution is just:

def uniform_pdf(x):
    return 1 if x >= 0 and x < 1 else 0

Shouldn't it be:

def uniform_pdf(x):
    return x if x >= 0 and x < 1 else 0

Best Answer

As you write, " the probability of seeing a value in a certain interval equals the integral of the density function over the interval." For the uniform distribution, the probability of seeing a value in the interval $[a,b]$ ($0\le a\le b\le1$) is $b-a$, and this agrees with $\int_a^b1\,dx$, not with $\int_a^bx\,dx$.