Skip to content

Introduction to Statistics in Python

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Add your notes here

# Calculate probability of waiting 10-20 mins 
prob_between_10_and_20 = uniform.cdf(20,0,30)-uniform.cdf(10,0,30)
#0 is the minimum and 30 is the maximum
print(prob_between_10_and_20)
# Calculate probability of waiting less than 5 mins
prob_less_than_5 = uniform.cdf(5,0,30)
#to calculate more we do 1-uniform
print(prob_less_than_5)
# Generate 1000 wait times between 0 and 30 mins
wait_times = uniform.rvs(0, 30, size=1000)
#The uniform.rvs() function takes in the minimum and maximum of the distribution you're working with, followed by number of wait times you want to generate.
print(wait_times)
#Simulate 1 deal worked on by Amir, who wins 30% of the deals he works on.
# Simulate a single deal
print(binom.rvs(1, 0.3, size=1))

# Simulate 1 week of 3 deals / Simulate a typical week of Amir's deals, or one week of 3 deals.
print(binom.rvs(3, 0.3, size=1))

# Simulate 52 weeks of 3 deals / Simulate a year's worth of Amir's deals, or 52 weeks of 3 deals each, and store in deals.
deals = binom.rvs(3, 0.3, size=52)
# Probability of closing 3 out of 3 deals
prob_3 = binom.pmf(3, 3, 0.3)

# Probability of closing <= 1 deal out of 3 deals
prob_less_than_or_equal_1 = binom.cdf(1, 3, 0.3)

# Probability of closing > 1 deal out of 3 deals
prob_greater_than_1 = 1- binom.cdf(1, 3, 0.3)
# Probability of deal < 7500
prob_less_7500 = norm.cdf(7500, 5000, 2000)
#probability, mean, sd

# Probability of deal > 1000
prob_over_1000 = 1-norm.cdf(1000, 5000, 2000)

# Probability of deal between 3000 and 7000
prob_3000_to_7000 = norm.cdf(7000, 5000, 2000)-norm.cdf(3000, 5000, 2000)

# Calculate amount that 25% of deals will be less than
pct_25 = norm.ppf(0.25, 5000, 2000)
# Generate 10 random heights
norm.rvs(161, 7, size=10)
#mean, sd, size
#to put a random seed
np.random.seed()

Perfect Poisson probabilities! Note that if you provide poisson.pmf() or poisson.cdf() with a non-integer, it throws an error since the Poisson distribution only applies to integers.