Created
January 30, 2024 18:48
-
-
Save smzn/a5f6f401825244f591042628a70b3fef to your computer and use it in GitHub Desktop.
事後予測分布で得られた点の分布
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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