Introduction to Statistics in Python
Maggie Matsui
Content Developer, DataCamp
What's the probability of an event?
$$ P(\text{event}) = \frac{\text{\# ways event can happen}}{\text{total \# of possible outcomes}} $$
Example: a coin flip
$$ P(\text{heads}) = \frac{\text{1 way to get heads}}{\text{2 possible outcomes}} = \frac{1}{2} = 50\%$$
$$P(\text{Brian}) = \frac{1}{4} = 25\%$$
print(sales_counts)
name n_sales
0 Amir 178
1 Brian 128
2 Claire 75
3 Damian 69
sales_counts.sample()
name n_sales
1 Brian 128
sales_counts.sample()
name n_sales
2 Claire 75
np.random.seed(10)
sales_counts.sample()
name n_sales
1 Brian 128
np.random.seed(10)
sales_counts.sample()
name n_sales
1 Brian 128
np.random.seed(10)
sales_counts.sample()
name n_sales
1 Brian 128
Sampling without replacement
$$P(\text{Claire}) = \frac{1}{3} = 33\%$$
sales_counts.sample(2)
name n_sales
1 Brian 128
2 Claire 75
$$P(\text{Claire}) = \frac{1}{4} = 25\%$$
sales_counts.sample(5, replace = True)
name n_sales
1 Brian 128
2 Claire 75
1 Brian 128
3 Damian 69
0 Amir 178
Two events are independent if the probability of the second event isn't affected by the outcome of the first event.
Two events are independent if the probability of the second event isn't affected by the outcome of the first event.
Sampling with replacement = each pick is independent
Two events are dependent if the probability of the second event is affected by the outcome of the first event.
Two events are dependent if the probability of the second event is affected by the outcome of the first event.
Two events are dependent if the probability of the second event is affected by the outcome of the first event.
Sampling without replacement → picks become dependent
Introduction to Statistics in Python