I've just tried to created graph of binomial distribution with python. Hence it's somewhat of memo of that:)
Prepare the calss of bernoulli trial
At first, I created python class of bernoulli trial which return probability of bernoulli trial with parameter n,k,p. Following is what I implemented.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.misc as scm | |
def bernoulli_trial_calc(n,k,p): | |
""" | |
Parameter | |
---------------- | |
n : number of statistically independent Bernoulli traial | |
k : the number of success | |
p : probability of success | |
Retrun | |
---------------- | |
Probability of this bernoulli traial | |
""" | |
return scm.comb(n,k) * ((p) **k) * ((1-p)**(n-k)) | |
class bernoulli_trial: | |
""" | |
class of beroulli_traial requeires two parameter n,p for initilization. | |
""" | |
def __init__(self,n,p): | |
""" | |
Parameter: | |
---------------- | |
n : number of statistically indepent Bernoulli trial | |
p : probabillity of success | |
""" | |
self.n = n | |
self.p = p | |
def calc(self,klist): | |
""" | |
Parameter: | |
---------------- | |
k : list of number of success | |
""" | |
prob_list = [] | |
for suc_num in klist: | |
prob_list.append(bernoulli_trial_calc(self.n,suc_num,self.p)) | |
return prob_list | |
if __name__ == '__main__': | |
n = 3 | |
p = 1/3 | |
ber_trial = bernoulli_trial(n,p) | |
klist = [0,1,2,3] | |
probability_list = ber_trial.calc(klist) | |
print(probability_list) |
Create graph of binomial distribution with various probability of success
Following is the graph with various probability of success in bernoulli trial.
From the result bellow, the vertex of probability distribution seems to be determined by probability of success in bernoulli trial.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Create graph of binomial distribution with various the number of bernoulli traial
Following is the graph with various number of bernoulli trial.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.