empirical cumulative distribution function to pdf in python code example
Example 1: cdf empírica python
from matplotlib import pyplot
from numpy.random import normal
from numpy import hstack
from statsmodels.distributions.empirical_distribution import ECDF
sample1 = normal(loc=20, scale=5, size=300)
sample2 = normal(loc=40, scale=5, size=700)
sample = hstack((sample1, sample2))
ecdf = ECDF(sample)
print('P(x<20): %.3f' % ecdf(20))
print('P(x<40): %.3f' % ecdf(40))
print('P(x<60): %.3f' % ecdf(60))
pyplot.plot(ecdf.x, ecdf.y)
pyplot.show()
Example 2: cdf empírica python
from matplotlib import pyplot
from numpy.random import normal
from numpy import hstack
sample1 = normal(loc=20, scale=5, size=300)
sample2 = normal(loc=40, scale=5, size=700)
sample = hstack((sample1, sample2))
pyplot.hist(sample, bins=50)
pyplot.show()