Lab 05 Presentation
Lab 05 Presentation
chances?
I N T R O D U C T I O N T O S TAT I S T I C S I N P Y T H O N
Maggie Matsui
Content Developer, DataCamp
Measuring chance
What's the probability of an event?
1
P (Brian) = = 25%
4
name n_sales
2 Claire 75
np.random.seed(10)
sales_counts.sample()
name n_sales
1 Brian 128
1
P (Claire) = = 33%
3
name n_sales
1 Brian 128
2 Claire 75
1
P (Claire) = = 25%
4
name n_sales
1 Brian 128
2 Claire 75
1 Brian 128
3 Damian 69
0 Amir 178
Maggie Matsui
Content Developer, DataCamp
Rolling the dice
number prob
0 1 0.166667 number prob
1 2 0.166667 0 1 0.166667
2 3 0.166667 0 1 0.166667
3 4 0.166667 4 5 0.166667
4 5 0.166667 1 2 0.166667
5 6 0.166667 0 1 0.166667
0 1 0.166667
5 6 0.166667
np.mean(die['number'])
5 6 0.166667
...
3.5
np.mean(rolls_10['number']) = 3.0
mean(die['number']) = 3.5
np.mean(rolls_100['number']) = 3.4
mean(die['number']) = 3.5
np.mean(rolls_1000['number']) = 3.48
mean(die['number']) = 3.5
Maggie Matsui
Content Developer, DataCamp
Waiting for the bus
0.5833333
0.4166667
0.25
Maggie Matsui
Content Developer, DataCamp
Coin flipping
1 = head, 0 = tails
array([1])
array([0, 1, 1, 0, 1, 0, 1, 1])
array([5])
array([0, 3, 2, 1, 3, 0, 2, 2, 0, 0])
array([1, 1, 1, 1, 0, 0, 2, 0, 1, 0])
Described by n and p
0.1171875
0.9453125
0.0546875
Maggie Matsui
Content Developer, DataCamp
What is the normal distribution?
Mean: 20
Standard deviation: 3
Mean: 0
Standard deviation: 1
0.158655
0.841345
0.1252
169.97086
152.029
Maggie Matsui
Content Developer, DataCamp
Rolling the dice 5 times
die = pd.Series([1, 2, 3, 4, 5, 6])
# Roll 5 times
samp_5 = die.sample(5, replace=True)
print(samp_5)
array([3, 1, 4, 1, 1])
np.mean(samp_5)
2.0
4.4
3.8
3.48
Maggie Matsui
Content Developer, DataCamp
Poisson processes
Events appear to happen at a certain rate,
but completely at random
Examples
Number of animals adopted from an
animal shelter per week
Examples
Probability of ≥ 5 animals adopted from an animal shelter per week
0.09160366
0.1912361
1 - poisson.cdf(5, 8)
0.8087639
If the average number of adoptions per week is 10, what is P (# adoptions in a week > 5)?
1 - poisson.cdf(5, 10)
0.932914