02 Experimental versus theoretical probability simulation#

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

khanacademy

Experimental versus theoretical probability simulation fig 1

def coin_trial():
    heads = 0
    for i in range(100):
        if random.random() <= 0.5:
            heads +=1
    return heads
coin_trial()
58
def simulate(n):
    trials = []
    for i in range(n):
        trials.append(coin_trial())
    return(sum(trials)/n)
simulate(1000)
50.136
# make similar simulation using numpy and shit get inspiration from DATACAMP

https://www.dataquest.io/blog/basic-statistics-in-python-probability/