04 Random numbers for experimental probability#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/vjGINFbV8Cs/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats

khanacademy

Random numbers for experimental probability fig 1

def three_rolls_to_ten():
    die = np.arange(1, 7, 1)
    choice = [np.random.choice(die) for i in range(3)]
    return choice, np.sum(choice)
df = DataFrame({'Experiement': [i+1 for i in range(10000)],
                'Sum': [three_rolls_to_ten()[1] for i in range(10000)]}).set_index('Experiement')
df['Win'] = df['Sum'] >= 10
df
Sum Win
Experiement
1 12 True
2 15 True
3 16 True
4 13 True
5 11 True
... ... ...
9996 10 True
9997 10 True
9998 13 True
9999 9 False
10000 11 True

10000 rows × 2 columns

val_count = df['Win'].value_counts()
val_count
True     6230
False    3770
Name: Win, dtype: int64
val_count[True] / val_count.sum() * 100
62.3