標本を測ってみよう
コイン投げの標本を使って、いくつかの確率を計算してみましょう。絶対度数と相対度数を計算し、標本データの分布から理論値を確認します。
配列 sample_of_two_coin_flips には、1,000 回の実験が入っています。各実験では、公平なコインを2回投げ、そのうち表の回数(0、1、2)を記録しています。
この演習では、scipy.stats ライブラリから binom オブジェクトと find_repeats()、relfreq() メソッドをあらかじめ読み込んであります。確率を計算するのにこれらを使います。
この演習はコースの一部です
Pythonで学ぶ確率の基礎
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Count how many times you got 2 heads from the sample data
count_2_heads = ____(sample_of_two_coin_flips).counts[2]
# Divide the number of heads by the total number of draws
prob_2_heads = count_2_heads / ____
# Display the result
print(prob_2_heads)