# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Coding Exercise #0301

# ### 1. Discrete probability distribution:

import scipy.stats as st
import matplotlib.pyplot as plt
import numpy as np
# %matplotlib inline

# #### 1.1. Binomial:

# Sample size and the p parameter.
n=10
p=0.5

# Probability distribution at x = 5.
st.binom.pmf(5, n, p)               

# Quantile at alpha = 0.3
# More about quantiles in the Unit III.
st.binom.ppf(0.3, n, p)             

# P(0 <= x <= 5)
st.binom.cdf(5,n,p)

# P(3 <= x <=7)
st.binom.cdf(7,n,p)-st.binom.cdf(2,n,p)        

# Visualizing the probability distribution.
x=np.arange(0,11)
plt.scatter(x, st.binom.pmf(x,n,p),color='red')
plt.show()

# #### 1.2. Poisson:

# The lambda parameter.
lamb = 2

# Probability distribution at x = 2.
st.poisson.pmf(2,lamb)             

# Quantile at alpha = 0.5
# More about quantiles in the Unit III.
st.poisson.ppf(0.5,lamb)                 

# P(0 <= x <= 5)
st.poisson.cdf(5,lamb)

# P(3 <= x <=7)
st.poisson.cdf(7,lamb)-st.poisson.cdf(2,lamb)

# Visualizing the probability distribution.
x=np.arange(0,11)
plt.scatter(x, st.poisson.pmf(x,lamb),color='green')
plt.show()



StarcoderdataJupyterScriptsDedupFiltered