<jupyter_start><jupyter_text>Distributions<jupyter_code>%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.stats import uniform, norm, bernoulli, binom, poisson, beta, gamma, nbinom, lognorm, geom, t, expon<jupyter_output><empty_output><jupyter_text>Discrete data* meaning: clear spaces between values* nature: countable* values: can take only distinct and separate values* graphical representation: bar graph* classification: mutually inclusive* function graph: shows isolated points* example: days of the weekWe use probability mass function to get the distribution  Bernoulli2 discrete outcomes (tail or head for a coin), the distribution over the discrete outcomes is 0 head, 1 tailprobability to get one over the other doesn't have to be 50%There is only one trial that gives us either head or tail<jupyter_code>data = bernoulli.rvs(size=1_000_000, p=0.5)
ax= sns.distplot(data,
                 kde=False,
                 color="lightgreen",
                 hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Bernoulli', ylabel='Frequency')
data = bernoulli.rvs(size=10_000, p=0.25)
ax= sns.distplot(data,
                 kde=False,
                 color="lightgreen",
                 hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Bernoulli', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>BinomialBinomial distribution is a sum of independent and evenly distributed Bernoulli trials2 possible choices (tail, head), what is the probability to have X tails ouf ot 10<jupyter_code>number_of_pick = 10
number_of_trial_repetition = 1_000_000
probability = 0.5

data = binom.rvs(n=number_of_pick, p=probability, size=number_of_trial_repetition)
ax = sns.distplot(data,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Number of successes (tail)', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Uniformevery possible result is equally likely; that is, the probability of each occurring is the same.<jupyter_code>data = uniform.rvs(size=1_000, loc = 0, scale = 10)
ax = sns.distplot(data,
                  bins=100,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Uniform ', ylabel='Frequency')
data = uniform.rvs(size=100_000, loc = 0, scale = 10)
ax = sns.distplot(data,
                  bins=100,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Uniform ', ylabel='Frequency')
data = uniform.rvs(size=1_000_000, loc = 0, scale = 10)
ax = sns.distplot(data,
                  bins=100,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Uniform ', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Poissonmodels the number of times an event happened in a time interval (number of users visit of a website for a specific time frame)mu is the number of times an event happens in this interval<jupyter_code>mu = 3

data = poisson.rvs(mu=mu, size=10_000)
ax = sns.distplot(data,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Number of cars passing in the street during the day', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Geometriccan mean two things:* probability distribution of the number X of Bernoulli trials needed to get one success* probability distribution of the number Y = X - 1 of failures before the first success<jupyter_code>p = 0.5

data = geom.rvs(p, size=1_000_000)
ax = sns.distplot(data,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Geometric', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Negative Binomialrandom variable with discerete outcome, related to binomial/bernoulli distribution<jupyter_code>data = nbinom.rvs(10, 0.5, size=10000)

ax = sns.distplot(data,
                  kde=False,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Negative Binomial', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Continous data* meaning: data that falls on a continuous sequence* nature: measurable* values: can take any value in some interval* graphical representation: histogram* classification: mutually exclusive* function graph: show connected points* example: market price of a productWe use probability density function to get the distribution. For a given range of value, the probability density function gives us a way of finding out the probability of that range occurring.  Normal (Gaussian)continuous probability distribution for a real valued random variable.Bell shape centered around a mean of 0<jupyter_code>mean = 0
variance = 1

data = norm.rvs(size=1_000_000, loc=mean, scale=variance)
ax = sns.distplot(data, bins=100, kde=False, color='lightgreen', hist_kws={'linewidth': 15, 'alpha': 1})
ax.set(xlabel='Normal', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Log-Normal<jupyter_code>data = lognorm.rvs(0.1, size=10_000_000)
ax = sns.distplot(data,kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Log Normal', ylabel='Frequency')
data = lognorm.rvs(0.3, size=10_000_000)
ax = sns.distplot(data,kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Log Normal', ylabel='Frequency')
data = lognorm.rvs(0.5, size=10_000_000)
ax = sns.distplot(data,kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Log Normal', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Student's tany member of a family of continuous probability distributions that arises when estimating the mean of a normally distributed population in situations where the sample size is small and the population standard deviation is unknown<jupyter_code>df = 5

data = t.rvs(df, size=1_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel="Student's t", ylabel='Frequency')
data = t.rvs(df, size=1_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel="Student's t", ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Gammatwo parameter (shape and scale) family of continuous probability distributions. Exponential, chi-squared, Erlang are special cases of the gamma distribution<jupyter_code>data = gamma.rvs(a=1, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Gamma', ylabel='Frequency')
data = gamma.rvs(a=5, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Gamma', ylabel='Frequency')
data = gamma.rvs(a=10, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Gamma', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Betadistribution for probabilities, continuous distribution taking values from 0 to 1Defined by two parameters alpha and beta<jupyter_code>alpha_param = 1
beta_param = 1

data = beta.rvs(alpha_param, beta_param, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(1,1)', ylabel='Frequency')
alpha_param = 10
beta_param = 1

data = beta.rvs(alpha_param, beta_param, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(1,1)', ylabel='Frequency')
alpha_param = 1
beta_param = 10

data = beta.rvs(alpha_param, beta_param, size=10_000_000)
ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(1,1)', ylabel='Frequency')<jupyter_output><empty_output><jupyter_text>Exponentialprobability distribution of the time between events in a Poisson point process -> a process in which events occur continuously and independently at a constant average rate<jupyter_code>data = expon.rvs(size=1_000_000)

ax = sns.distplot(data,
                  kde=False,
                  bins=100,
                  color='lightgreen',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Exponential', ylabel='Frequency')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup