Proeven van Bayes

Bayesian Data Analysis in Python

Michal Oleszak

Machine Learning Engineer

Binomiale verdeling

  • Een discrete verdeling, neemt slechts twee waarden aan:
    • Succes (1)
    • Mislukking (0)
  • Eén parameter: kans op succes.
  • Taak: gegeven een lijst worpen (successen en missers), schat de kans op succes.
Bayesian Data Analysis in Python

Binomiale verdeling in Python

Aantal successen in 100 pogingen:

import numpy as np
np.random.binomial(100, 0.5)
51

 

np.random.binomial(100, 0.5)
44

Steekproeven uit een binomiale verdeling:

import numpy as np
np.random.binomial(1, 0.5, size=5)
array([1, 0, 0, 1, 1])
Bayesian Data Analysis in Python

Kans op kop

  • get_heads_prob() - een eigen functie
  • input: een lijst met muntworpen
  • output: een lijst, de verdeling van de kans op kop

 

import numpy as np
tosses = np.random.binomial(1, 0.5, size=1000)
print(tosses)
[1 0 0 0 1 1 0 1 1 ... ]
Bayesian Data Analysis in Python

Kans op kop

heads_prob = get_heads_prob(tosses)
print(heads_prob)
[0.47815295 0.51679212 0.51684779 ... ]
import matplotlib.pyplot as plt
import seaborn as sns

sns.kdeplot(heads_prob, 
            shade=True, 
            label="heads probabilty")
plt.show()

Een symmetrische, klokvormige curve met een piek rond X-aswaarde 0,51.

Bayesian Data Analysis in Python

Laten we munten gooien!

Bayesian Data Analysis in Python

Preparing Video For Download...