Copyright 2019 Allen Downey
BSD 3-clause license: https://opensource.org/licenses/BSD-3-Clause
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from empiricaldist import Pmf
pmf = Pmf.from_seq([1, 2, 2, 4, 5], name='example')
pmf.plot()
plt.legend();
No handles with labels found to put in legend.
pmf.bar()
plt.legend();
No handles with labels found to put in legend.
xs = [1,2,3,4]
ys = [0.15, 0.35, 0.25, 0.2]
pmf.plot()
plt.plot(xs, ys)
[<matplotlib.lines.Line2D at 0x7f20eee1e410>]
cdf = pmf.make_cdf()
cdf.plot()
plt.legend();
No handles with labels found to put in legend.
cdf.step()
plt.legend();
No handles with labels found to put in legend.
surv = cdf.make_surv()
surv.plot()
plt.legend();
No handles with labels found to put in legend.
surv = cdf.make_surv()
surv.step()
plt.legend();
No handles with labels found to put in legend.
haz = surv.make_hazard()
haz.plot()
plt.legend();
No handles with labels found to put in legend.
haz.bar()
plt.legend();
No handles with labels found to put in legend.
unbiased = np.array([ 5, 6, 12, 7, 8, 6, 6, 9, 8, 4, 3, 5, 5, 7, 5, 7, 4,
4, 3, 6, 3, 5, 10, 1, 7, 4, 8, 2, 9, 6, 5, 5, 9, 11,
11, 3, 9, 1, 10, 1, 6, 6, 5, 8, 7, 7, 4, 7, 2, 1, 3,
1, 6, 3, 1, 1, 2, 2, 1, 2, 2, 1])
pmf = Pmf.from_seq(unbiased)
pmf.bar(label='')
from scipy.stats import poisson
mean = np.mean(unbiased)
qs = np.arange(1, 13)
ps = poisson.pmf(qs, mean)
plt.plot(qs, ps, color='C1', label='model')
[<matplotlib.lines.Line2D at 0x7f20ee1828d0>]
pmf.bar()
plt.plot(qs, ps, color='C1', label='model')
[<matplotlib.lines.Line2D at 0x7f20ee0e5d90>]