<jupyter_start><jupyter_text>Create PMF Functions<jupyter_code># Binomial PMF
def n_choose_k(n, k):
    return fact(n) / (fact(k)*(fact(n-k)))

def binomial(n, k, p):
    '''
    n = number of trials
    k = number of successes
    p = probability of success
    return probability of k successes
    '''
    return n_choose_k(n, k) * p**k * (1-p)**(n-k)

# Geometric 
def geometric(p, k):
    '''
    k = kth trial
    p = probability of success
    return probability of first success on kth trial
    '''
    return (1-p)**(k-1) * p

# Poisson PMF
def poisson(lam, k):
    '''
    lam = expected successes in time interval
    k = number of successes
    return probability of k successes
    '''
    return lam**k * exp(-lam) / fact(k)

def myround(x, base=5):
    x = float(int(x*100))
    return int(base * int(x/base))/100 + .05<jupyter_output><empty_output><jupyter_text>Probability Questions Binomial: k successes out of n trials1. Probability of getting 7 heads out of 20 coin flips with a fair coin.2. Probability of getting between 3 and 7 heads out of 20 coin flips with an unfair coin that lands on heads 75% of the time.3. What is the probability of rolling doubles 10 times out of 100 rolls when rolling two six-sided die?4. Sean has the strength advantage but with Erin's piano background she has very dexterous thumbs.  When they thumb wrestle Erin wins 75% of the time.  What is the probabilty that out of 10 Thumb Wrestlng matches Sean wins more than 8 times? Geometric: first success on kth trial1. Probability of not flipping heads until the 5th flip with a fair coin.2. Probability of rolling doubles on your first roll.3. Sean's baby, Dayton, pukes once for every three feedings and is fed 9 times a day.  What is the probability that she won't puke for a full day of feedings? Poisson: probabilty of k successes over a time interval1. Dr. Evil tries to take over the world once every 2 years.  What is the probability that he doesn't try to take over the world in the next 10 years?2. Dayton pukes on Sean 3 times a day. What is the probabilty he gets puked on 15 times in one week?3. On average 4 students make it this far in the assignment what is the probability that between 6 and 10 students do this time?4. Dr. Evil has a pool of sharks with laser beams attached to their foreheads, wher he executes prisoners, but he has a tendency to monologue, about his datardly plan for world domination, during which a prisoner escapes every 5 minutes.  If he monologues for 10 what is the probability that a prisoner gets away safely?  Answers 1. Probability of getting 7 heads out of 20 coin flips with a fair coin.<jupyter_code># Binomial Distribution

n = 20
p = .5
k = 7
mu = n*p

# Equation
p1 = binomial(n, k, p)

# Scipy Stats PMF
p2 = s.binom.pmf(k=k, n=n, p=p)

# Scipy Stats CDF
p3 = s.binom.cdf(k=k, n=n, p=p) - s.binom.cdf(k=k-1, n=n, p=p)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.0739, scipy.pmf: 0.0739, scipy.cdf: 0.0739<jupyter_text>2. Probability of not flipping heads until the 5th flip with a fair coin.<jupyter_code># Geometric Distribution

p = .5
k = 5
mu = 1/p

# Equation
p1 = geometric(p, k)

# Scipy Stats PMF
p2 = s.geom.pmf(p=p, k=k)

# Scipy Stats CDF
p3 = s.geom.cdf(p=p, k=k) - s.geom.cdf(p=p, k=k-1)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.0312, scipy.pmf: 0.0312, scipy.cdf: 0.0312<jupyter_text>3. Dr. Evil tries to take over the world once every 2 years.  What is the probability that he doesn't try to take over the world in the next 10 years?<jupyter_code># Poisson Distribution

lam = .5 * 10
k = 0

# Equation
poisson1 = poisson(lam=lam, k=k)

# Scipy Stats PMF
poisson2 = s.poisson.pmf(k=k, mu=lam)

# Scipy Stats CDF
poisson3 = s.poisson.cdf(k=k, mu=lam)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(poisson1, poisson2, poisson3))<jupyter_output>Formula: 0.0067, scipy.pmf: 0.0067, scipy.cdf: 0.0067<jupyter_text>4. Probability of getting between 3 and 7 (inclusive) heads out of 20 coin flips with an unfair coin that lands on heads 75% of the time. (Binomial)<jupyter_code># Binomial Distribution

n = 20
p = .5
ks = list(range(3, 8))
mu = n*p

# Equation
p1 = 0
for k in ks:
    p1 += binomial(n, k, p)

# Scipy Stats PMF
p2 = 0
for k in ks:
    p2 += s.binom.pmf(k=k, n=n, p=p)

# Scipy Stats CDF
p3 = s.binom.cdf(k=ks[-1], n=n, p=p) - s.binom.cdf(k=ks[0]-1, n=n, p=p)


print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>7
2
Formula: 0.1314, scipy.pmf: 0.1314, scipy.cdf: 0.1314<jupyter_text>5. Dr. Evil has a pool of sharks with laser beams attached to their foreheads, wher he executes prisoners, but he has a tendency to monologue, about his datardly plan for world domination, during which a prisoner escapes every 5 minutes.  If he monologues for 10 what is the probability that a prisoner gets away safely?<jupyter_code># Poisson Distribution

lam = 1 * 2
k = 1

# Equation
poisson1 = poisson(lam=lam, k=k)

# Scipy Stats PMF
poisson2 = s.poisson.pmf(k=k, mu=lam)

# Scipy Stats CDF
poisson3 = s.poisson.cdf(k=k, mu=lam) - s.poisson.cdf(k=k-1, mu=lam)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(poisson1, poisson2, poisson3))<jupyter_output>Formula: 0.2707, scipy.pmf: 0.2707, scipy.cdf: 0.2707<jupyter_text>6. What is the probability of rolling doubles 10 times out of 100 rolls when rolling two six-sided die?<jupyter_code># Binomial Distribution

n = 100
p = 6/36
k = 10
mu = n*p

# Equation
p1 = binomial(n, k, p)

# Scipy Stats PMF
p2 = s.binom.pmf(k=k, n=n, p=p)

# Scipy Stats CDF
p3 = s.binom.cdf(k=k, n=n, p=p) - s.binom.cdf(k=k-1, n=n, p=p)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.0214, scipy.pmf: 0.0214, scipy.cdf: 0.0214<jupyter_text>7. Sean has the strength advantage but with Erin's piano background she has very dexterous thumbs--when they thumb wrestle Erin wins 75% of the time.  What is the probabilty that out of 10 thumb wrestlng matches Sean wins more than 8 times?<jupyter_code># Binomial Distribution

n = 20
p = .5
ks = list(range(8, 21))
mu = n*p

# Equation
p1 = 0
for k in ks:
    p1 += binomial(n, k, p)

# Scipy Stats PMF
p2 = 0
for k in ks:
    p2 += s.binom.pmf(k=k, n=n, p=p)

# Scipy Stats CDF
p3 = s.binom.cdf(k=ks[-1], n=n, p=p) - s.binom.cdf(k=ks[0]-1, n=n, p=p)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.8684, scipy.pmf: 0.8684, scipy.cdf: 0.8684<jupyter_text>8. Probability of rolling doubles on your first roll when rolling two six-sided die?<jupyter_code># Geometric Distribution

p = 6/36
k = 1
mu = 1/p

# Equation
p1 = geometric(p, k)

# Scipy Stats PMF
p2 = s.geom.pmf(p=p, k=k)

# Scipy Stats CDF
p3 = s.geom.cdf(p=p, k=k) - s.geom.cdf(p=p, k=k-1)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.1667, scipy.pmf: 0.1667, scipy.cdf: 0.1667<jupyter_text>9. Sean's baby, Dayton, pukes once for every three feedings and is fed 9 times a day.  What is the probability that she won't puke for a full day of feedings?<jupyter_code># Geometric Distribution

p = 1/3
k = 10
mu = 1/p

# Equation
p1 = geometric(p, k)

# Scipy Stats PMF
p2 = s.geom.pmf(p=p, k=k)

# Scipy Stats CDF
p3 = s.geom.cdf(p=p, k=k) - s.geom.cdf(p=p, k=k-1)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(p1, p2, p3))<jupyter_output>Formula: 0.0087, scipy.pmf: 0.0087, scipy.cdf: 0.0087<jupyter_text>10. Dayton pukes on Sean 3 times a day. What is the probabilty he gets puked on 15 times in one week?<jupyter_code># Poisson Distribution

lam = 3 * 7
k = 15

# Equation
poisson1 = poisson(lam=lam, k=k)

# Scipy Stats PMF
poisson2 = s.poisson.pmf(k=k, mu=lam)

# Scipy Stats CDF
poisson3 = s.poisson.cdf(k=k, mu=lam) - s.poisson.cdf(k=k-1, mu=lam)

print('Formula: {:.4f}, scipy.pmf: {:.4f}, scipy.cdf: {:.4f}'.format(poisson1, poisson2, poisson3))<jupyter_output>Formula: 0.0395, scipy.pmf: 0.0395, scipy.cdf: 0.0395
{'fraction_non_alphanumeric': 0.13367672308069659, 'fraction_numerical': 0.05003679175864607, 'mean_word_length': 3.9274924471299095, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '621397', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3721, 'n_tokens_neox': 3342, 'n_words': 1096, 'path': 'distributions_ass_answers.ipynb', 'repo_name': 'GalvanizeOpenSource/bdr-platte-intro-to-ds-oct-2018', 'size': '8154'}