Week 9 - Activity 6
Week 9 - Activity 6
Module used
'''
as m1 = alpha/beta
m2 = a^2/b^2 + a/b^2
'''
fig, ax = plt.subplots(1,1)
ax.hist(rec_imdb_arr, density=True, bins= 10)
xx = np.linspace(0,10,5000)
ax.plot(xx, st.gamma.pdf(xx,alphamm,scale = 1/betamm), label='gamm
ax.legend(loc='best')
plt.show()
ax_1 = plt.subplot(121)
ax_1.hist(alpha_hat, density=True)
ax_2 = plt.subplot(122)
ax_2.hist(beta_hat, density=True)
#now calculating square standard deviation
print('variance of Alpha_hat', np.sqrt(np.var(alpha_hat)))
print('Variance of Beta_Hat', np.sqrt(np.var(beta_hat)))
plt.show()
fig , ax = plt.subplots(1,1)
xx = np.linspace(0.01, 2, 50)
ax.plot(xx, f_ML(xx))
ax.grid(True)
plt.show()
# 95% of confidence interval for alpha using the method of moments
# Work out to be
#[14.552 - 1.689, 14.552 - (-1.349)]
95% of confidence interval for alpha using the method of moments estimator
Work out to be
In [10]:
# Now solving numerically
import scipy.optimize as spot
sol = spot.root_scalar(f_ML, bracket=[0.01,1000])
sol.root # don't Know why it is throwing this value
In [11]:
alpha_ml = sol.root
beta_ml = alpha_ml/ exp_1
print('Alpha_ml :', alpha_ml)
print('Beta_ml:', beta_ml)
Alpha_ml : 12.480431978112412
Beta_ml: 2.174957505090638
Conclusion
From above graph it's clear that
Both ML and MM are not able to provide batter approximation for above data.