I am trying to understand SciPy Binomial, I am making no headway with the scipy manual.
I can simulate a coin flip with NumPy random.
import numpy as np
print('Simulating the result of a single fair coin flip ')
n = 1
p = 0.5
result = np.random.binomial(n,p)
if result == 1:
print('1')
print('Heads')
else:
print('0')
print('tails')
I also came across this code for NumPy which simulates a random probability of getting 6 heads in a row out of 20000 flips
import numpy as np
simulation = sum(np.random.binomial(6, 0.5,20000)==6)/20000
print(simulation)
However I am not looking to run a random simulation, I would like to use SciPy binomial to show me the actual probability of binomial test, e.g. 0.5 for a single coin flip
When I run the SciPy code below
from scipy.stats import binom
n, p = 1,0.5
result = binom.stats(n,p)
print(result)
I get this result
(array(0.5), array(0.25))
Can anyone help explain how I use SciPy properly to get the result of 0.5 for a single coin flip, and any other syntax I require to calculate how to use SciPy to show binomial probability of 5 heads in 20000 coin flips.
I realize that there are other mathematical ways to do this, but it is SciPy I am trying to learn.