<jupyter_start><jupyter_text>연습문제 9.3.1<jupyter_code>xx = np.linspace(0, 1, 1000)

# 상품 A의 사후 확률
a0, b0 = 2+1, 1+1
plt.plot(xx, sp.stats.beta(a0, b0).pdf(xx), c='r', ls = '--', label = '상품 A의 사후분포')

#상품 B의 사후 확률
a1, b1 = 60+1, 40+1
plt.plot(xx, sp.stats.beta(a1, b1).pdf(xx), c='g', ls = '-', label = '상품 B의 사후분포')

plt.title('베르누이분포의 모수를 베이즈 추정법으로 추정한 결과')<jupyter_output><empty_output><jupyter_text>연습문제 9.3.2<jupyter_code>from sklearn.datasets import load_iris
iris = load_iris()
x = iris.data[:, 0]
N = len(x)
mu = np.mean(x)
sigma2 = np.var(x)
print("sample mean:", mu)
print("sample variance:", sigma2)
sns.distplot(x, kde=False, fit=sp.stats.norm)
plt.vlines(x=mu, ymin=0, ymax=0.6, ls="--")
plt.vlines(x=mu+2*np.sqrt(sigma2), ymin=0, ymax=0.6, ls=":")
plt.vlines(x=mu-2*np.sqrt(sigma2), ymin=0, ymax=0.6, ls=":")
plt.show()<jupyter_output>sample mean: 5.843333333333334
sample variance: 0.6811222222222223
{'fraction_non_alphanumeric': 0.21444201312910285, 'fraction_numerical': 0.08643326039387308, 'mean_word_length': 5.398601398601398, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '36508', 'license': 'MIT', 'n_tokens_mistral': 546, 'n_tokens_neox': 551, 'n_words': 87, 'path': 'math/11_math_day11_0506.ipynb', 'repo_name': 'hnryu0311/TIL', 'size': '914'}