Checking the result
Now try generating some samples and calculating the expected value and variance yourself, then using the method provided by binom to check if the sample values match the theoretical values.
The binom object and describe() method from scipy.stats are already loaded, so you can make the calculations.
Diese Übung ist Teil des Kurses
Foundations of Probability in Python
Anleitung zur Übung
- Calculate the sample mean and variance of the
samplevariable. - Calculate the expected value using
n=10andp=0.3, and calculate the variance usingmean, and1 - p. - Use a
binommethod to get the expected value and variance for 10 coin flips withp=0.3.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
sample = binom.rvs(n=10, p=0.3, size=2000)
# Calculate the sample mean and variance from the sample variable
sample_describe = describe(____)
# Calculate the sample mean using the values of n and p
mean = ____*____
# Calculate the sample variance using the value of 1-p
variance = mean*____
# Calculate the sample mean and variance for 10 coin flips with p=0.3
binom_stats = binom.stats(n=____, p=____)
print(sample_describe.mean, sample_describe.variance, mean, variance, binom_stats)