Skip to content

Instantly share code, notes, and snippets.

@smzn
Created January 30, 2024 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smzn/a5f6f401825244f591042628a70b3fef to your computer and use it in GitHub Desktop.
Save smzn/a5f6f401825244f591042628a70b3fef to your computer and use it in GitHub Desktop.
事後予測分布で得られた点の分布
from scipy.stats import nbinom
# 新しいデータ点 x_new が取り得る値の範囲
x_new_values = range(0, daily_sales.max())
# 事後予測分布を計算(負の二項分布を使用)
p_pred = [nbinom.pmf(k=x_new, n=alpha_posterior, p=beta_posterior/(1+beta_posterior)) for x_new in x_new_values]
# 結果をプロット
import matplotlib.pyplot as plt
plt.bar(x_new_values, p_pred, color='blue', alpha=0.7)
plt.title('Posterior Predictive Distribution')
plt.xlabel('x_new')
plt.ylabel('Probability')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment