การวิเคราะห์ข้อมูลแบบเบย์เซียนด้วย Python
Michal Oleszak
Machine Learning Engineer




ความเชื่อเบื้องต้นของเรา: หัวมีโอกาสออกน้อยกว่า

บางตัวเลือกดีกว่าตัวอื่น!

numpyget_heads_prob() จากบทที่ 1:def get_heads_prob(tosses):
num_heads = np.sum(tosses)
# prior: Beta(1,1)
return np.random.beta(num_heads + 1, len(tosses) - num_heads + 1, 1000)
การจำลอง
numpy:draws = np.random.beta(2, 4, 1000)
array([0.05941031, ..., 0.70015975])
sns.kdeplot(draws)
การคำนวณ
head_prob posterior_prob
0 0.00 0.009901
1 0.01 0.003624
... ...
10199 0.99 0.003624
10200 1.00 0.009901
sns.lineplot(df["head_prob"], df["posterior_prob"])
การวิเคราะห์ข้อมูลแบบเบย์เซียนด้วย Python