# Distribuição Normal

Gaussiana, curva de sino

* simétrica
* média = mediana = moda
* variáveis contínuas

Ex:
* altura e peso de uma população
* tamanho do crânio de recém nascidos
* pressão sanguínea

$$ p(x|\mu,\sigma) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left[-\frac{(x-\mu)^2}{2\sigma^2}\right] $$



```
import matplotlib.pyplot as plt

SMALL_SIZE = 12
MEDIUM_SIZE = 14
BIGGER_SIZE = 16

# Font Sizes 
plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title

plt.rc('figure', figsize = (8, 6)) # Figure Size
```


```
import numpy as np
from scipy.stats import norm
import math


mu = 0
variance = 1
sigma = np.sqrt(variance)
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)

p = 1/np.sqrt(2*math.pi*sigma**2)*np.exp(-(x-mu)**2/(2*sigma**2))

plt.plot(x, norm.pdf(x, mu, sigma), label='scipy')
plt.plot(x, p, 'k:', lw=5, label='formula')

plt.legend();
```


```
x = np.linspace(-5, 5, 100)

mu = 0
sigma = 1
plt.plot(x,norm.pdf(x, mu, sigma), 'k:', lw=5, 
         label=r'$\mu={}, \sigma={}$'.format(mu,sigma))

mu = 1
sigma = 1.5
plt.plot(x,norm.pdf(x, mu, sigma), 'r-.', lw=2, 
         label=r'$\mu={}, \sigma={}$'.format(mu,sigma))

mu = -1
sigma = .75
plt.plot(x,norm.pdf(x, mu, sigma), 'g', lw=3, 
         label=r'$\mu={}, \sigma={}$'.format(mu,sigma))


plt.legend();
```

Z_score

$$ z_i = \frac{x_i-\bar{x}}{\sigma} $$

# Distribuição

* Variáveis Contínuas
 * Normal
 * Exponencial
 * Gamma

* Variáveis Discretas
 * Binomial
 * Poisson

# Distribuição binomial

* variáveis discretas
* dois resultados possíveis de igual chance de ocorrência
* eventos finitos e independentes

Ex.:
* Dado
* Moeda


$$ p(k|n,p) = \frac{n!}{k!(n-k)!}p^k(1-p)^{n-k} $$


```
from math import factorial
from scipy.stats import binom

n = 50 
p = 0.5
k_vec = np.arange(1,n+1) # target, starts at 1 goes to n, all possible outcomes

def compute_binomial_prob(n,k,p):
  return factorial(n)/(factorial(k)*factorial(n-k)) * p**k * (1-p)**(n-k)

P_vec = [compute_binomial_prob(n,k,p) for k in k_vec]

plt.plot(k_vec, binom.pmf(k_vec, n, p), 'r', label='scipy')
plt.plot(k_vec, P_vec, 'k:', lw=5, label='formula')




plt.legend();

```

Ex: https://towardsdatascience.com/fun-with-the-binomial-distribution-96a5ecabf65b


```
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Input variables
# Number of trials
trials = 1000
# Number of independent experiments in each trial
n = 10
# Probability of success for each experiment
p = 0.5
# Function that runs our coin toss trials (Monte Carlo)
# heads is a list of the number of successes from each trial of n experiments
def run_binom(trials, n, p):
    heads = []
    for i in range(trials):
        tosses = [np.random.random() for i in range(n)]
        heads.append(len([i for i in tosses if i>=0.50]))
    return heads
# Run the function
heads = run_binom(trials, n, p)
# Plot the results as a histogram
fig, ax = plt.subplots(figsize=(14,7))
ax = sns.distplot(heads, bins=11, label='simulation results')
ax.set_xlabel("Number of Heads",fontsize=16)
ax.set_ylabel("Frequency",fontsize=16);
```


```
# Plot the actual binomial distribution as a sanity check
from scipy.stats import binom
x = range(0,11)
plt.plot(x, binom.pmf(x, n, p), 'ro', label='actual binomial distribution')
plt.vlines(x, 0, binom.pmf(x, n, p), colors='r', lw=5, alpha=0.5)
plt.legend()
plt.show()
```


```
# Probability of getting 6 heads
runs = 10000
prob_6 = sum([1 for i in np.random.binomial(n, p, size=runs) if i==6])/runs
print('The probability of 6 heads is: ' + str(prob_6))
```

    The probability of 6 heads is: 0.201



```
# Call Center Simulation
# Number of employees to simulate
employees = 100
# Cost per employee
wage = 200
# Number of independent calls per employee
n = 50
# Probability of success for each call
p = 0.04
# Revenue per call
revenue = 100
# Binomial random variables of call center employees
conversions = np.random.binomial(n, p, size=employees)
# Print some key metrics of our call center
print('Average Conversions per Employee: ' + str(round(np.mean(conversions), 2)))
print('Standard Deviation of Conversions per Employee: ' + str(round(np.std(conversions), 2)))
print('Total Conversions: ' + str(np.sum(conversions)))
print('Total Revenues: ' + str(np.sum(conversions)*revenue))
print('Total Expense: ' + str(employees*wage))
print('Total Profits: ' + str(np.sum(conversions)*revenue - employees*wage))

# Number of days to simulate
sims = 1000
sim_conversions = [np.sum(np.random.binomial(n, p, size=employees)) for i in range(sims)]
sim_profits = np.array(sim_conversions)*revenue - employees*wage
```

    Average Conversions per Employee: 1.72
    Standard Deviation of Conversions per Employee: 1.28
    Total Conversions: 172
    Total Revenues: 17200
    Total Expense: 20000
    Total Profits: -2800



```
# Call Center Simulation (Higher Conversion Rate)
# Number of employees to simulate
employees = 100
# Cost per employee
wage = 200
# Number of independent calls per employee
n = 55
# Probability of success for each call
p = 0.05
# Revenue per call
revenue = 100
# Binomial random variables of call center employees
conversions_up = np.random.binomial(n, p, size=employees)
# Simulate 1,000 days for our call center
# Number of days to simulate
sims = 1000

sim_conversions_up = [np.sum(np.random.binomial(n, p, size=employees)) for i in range(sims)]
sim_profits_up = np.array(sim_conversions_up)*revenue - employees*wage
# Plot and save the results as a histogram
fig, ax = plt.subplots(figsize=(14,7))
ax = sns.distplot(sim_profits, bins=20, label='original call center simulation results')
ax = sns.distplot(sim_profits_up, bins=20, label='improved call center simulation results', color='red')
ax.set_xlabel("Profits",fontsize=16)
ax.set_ylabel("Frequency",fontsize=16)
plt.legend();
```

Ex: https://cmdlinetips.com/2018/03/probability-distributions-in-python/


https://www.probabilisticworld.com/discrete-probability-distributions-overview/


```
# for inline plots in jupyter
%matplotlib inline
# import matplotlib
import matplotlib.pyplot as plt
# import seaborn
import seaborn as sns
# settings for seaborn plotting style
sns.set(color_codes=True)
# settings for seaborn plot sizes
sns.set(rc={'figure.figsize':(4.5,3)})
```

# Uniform distribution

$$ P(x;n) = \frac{1}{n} $$


```
# import uniform distribution
from scipy.stats import uniform

# random numbers from uniform distribution
# Generate 10 numbers from 0 to 10
n = 10000
a = 0
b = 10
data_uniform = uniform.rvs(size=n, loc = a, scale=b) #random variables

ax = sns.distplot(data_uniform,
                  bins=100,
                  kde=False, # density plot
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Uniform ', ylabel='Frequency');
```

# Normal distribution

$$ p(x|\mu,\sigma) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left[-\frac{(x-\mu)^2}{2\sigma^2}\right] $$


```
from scipy.stats import norm

# generate random numbers from N(0,1)
data_normal = norm.rvs(size=10000,loc=0,scale=1)  # loc = mean, scale = std

ax = sns.distplot(data_normal,
                  bins=100,
                  kde=False,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Normal', ylabel='Frequency');
```

# Bernoulli distribution

Discrete. Outcome: 0 or 1.


\begin{equation}
P(x;p) = \begin{cases}
p &\text{if $x=1$}\\
1-p &\text{if $x=0$}
\end{cases}
\end{equation}



```
# import bernoulli
from scipy.stats import bernoulli

# generate bernoulli
data_bern = bernoulli.rvs(size=10000,p=0.3)
ax= sns.distplot(data_bern,
                 kde=False,
                 color="skyblue",
                 hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Bernoulli', ylabel='Frequency');


```

# Binomial distribution

Discrete.
Obtains the number of successe from N Bernoulli trials.

$$ p(k|n,p) = \frac{n!}{k!(n-k)!}p^k(1-p)^{n-k} $$

\begin{equation}
p(x; p,n) = \binom{n}{x}p^{x}(1-p)^{n-x}
\end{equation}


```
from scipy.stats import binom

binom.rvs(n=10,p=0.5) # sucesses from n=10 Bernoulli trials with p=0.5


data_binom = binom.rvs(n=10,p=0.5,size=10000)
ax = sns.distplot(data_binom,
                  kde=False,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Binomial', ylabel='Frequency');

```

# Poisson distribution

number of times an event happened in a time interval

* rate of ocurrence (mu)

$$ P(x;\mu)=\frac{\mu^x e^{-\mu}}{x!} $$


```
from scipy.stats import poisson

data_poisson = poisson.rvs(mu=3, size=10000)
ax = sns.distplot(data_poisson,
                  kde=False,
                  color='green',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Poisson', ylabel='Frequency');
```

# Beta distribution

* Continuous
* distribution for probabilities


```
from scipy.stats import beta

data_beta = beta.rvs(1, 1, size=10000) # ~ uniform
ax = sns.distplot(data_beta,
                  kde=False,
                  bins=100,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(1,1)', ylabel='Frequency');
```


```
data_beta_a10b1 = beta.rvs(10, 1, size=10000) #skewed right
ax = sns.distplot(data_beta_a10b1,
             kde=False,
             bins=50,
             color='skyblue',
             hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(10,1)', ylabel='Frequency');
```


```
data_beta_a1b10 = beta.rvs(1, 10, size=10000) # skewed leftt
ax = sns.distplot(data_beta_a1b10,
                kde=False,
                bins=100,
                color='skyblue',
                hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(1,10)', ylabel='Frequency');
```


```
data_beta_a10b10 = beta.rvs(10, 10, size=10000) # ~ normal
ax = sns.distplot(data_beta_a10b10,
                  kde=False,
                  bins=100,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Beta(10,10)', ylabel='Frequency');
```

# Gamma distribution




```
from scipy.stats import gamma

data_gamma = gamma.rvs(a=5, size=10000)
ax = sns.distplot(data_gamma,
                  kde=False,
                  bins=100,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Gamma', ylabel='Frequency');
```


```
help(gamma)
```

    Help on gamma_gen in module scipy.stats._continuous_distns object:
    
    class gamma_gen(scipy.stats._distn_infrastructure.rv_continuous)
     |  A gamma continuous random variable.
     |  
     |  %(before_notes)s
     |  
     |  See Also
     |  --------
     |  erlang, expon
     |  
     |  Notes
     |  -----
     |  The probability density function for `gamma` is:
     |  
     |  .. math::
     |  
     |      f(x, a) = \frac{x^{a-1} \exp(-x)}{\Gamma(a)}
     |  
     |  for :math:`x \ge 0`, :math:`a > 0`. Here :math:`\Gamma(a)` refers to the
     |  gamma function.
     |  
     |  `gamma` takes ``a`` as a shape parameter for :math:`a`.
     |  
     |  When :math:`a` is an integer, `gamma` reduces to the Erlang
     |  distribution, and when :math:`a=1` to the exponential distribution.
     |  
     |  %(after_notes)s
     |  
     |  %(example)s
     |  
     |  Method resolution order:
     |      gamma_gen
     |      scipy.stats._distn_infrastructure.rv_continuous
     |      scipy.stats._distn_infrastructure.rv_generic
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  fit(self, data, *args, **kwds)
     |      Return MLEs for shape (if applicable), location, and scale
     |      parameters from data.
     |      
     |      MLE stands for Maximum Likelihood Estimate.  Starting estimates for
     |      the fit are given by input arguments; for any arguments not provided
     |      with starting estimates, ``self._fitstart(data)`` is called to generate
     |      such.
     |      
     |      One can hold some parameters fixed to specific values by passing in
     |      keyword arguments ``f0``, ``f1``, ..., ``fn`` (for shape parameters)
     |      and ``floc`` and ``fscale`` (for location and scale parameters,
     |      respectively).
     |      
     |      Parameters
     |      ----------
     |      data : array_like
     |          Data to use in calculating the MLEs.
     |      args : floats, optional
     |          Starting value(s) for any shape-characterizing arguments (those not
     |          provided will be determined by a call to ``_fitstart(data)``).
     |          No default value.
     |      kwds : floats, optional
     |          Starting values for the location and scale parameters; no default.
     |          Special keyword arguments are recognized as holding certain
     |          parameters fixed:
     |      
     |          - f0...fn : hold respective shape parameters fixed.
     |            Alternatively, shape parameters to fix can be specified by name.
     |            For example, if ``self.shapes == "a, b"``, ``fa``and ``fix_a``
     |            are equivalent to ``f0``, and ``fb`` and ``fix_b`` are
     |            equivalent to ``f1``.
     |      
     |          - floc : hold location parameter fixed to specified value.
     |      
     |          - fscale : hold scale parameter fixed to specified value.
     |      
     |          - optimizer : The optimizer to use.  The optimizer must take ``func``,
     |            and starting position as the first two arguments,
     |            plus ``args`` (for extra arguments to pass to the
     |            function to be optimized) and ``disp=0`` to suppress
     |            output as keyword arguments.
     |      
     |      Returns
     |      -------
     |      mle_tuple : tuple of floats
     |          MLEs for any shape parameters (if applicable), followed by those
     |          for location and scale. For most random variables, shape statistics
     |          will be returned, but there are exceptions (e.g. ``norm``).
     |      
     |      Notes
     |      -----
     |      This fit is computed by maximizing a log-likelihood function, with
     |      penalty applied for samples outside of range of the distribution. The
     |      returned answer is not guaranteed to be the globally optimal MLE, it
     |      may only be locally optimal, or the optimization may fail altogether.
     |      If the data contain any of np.nan, np.inf, or -np.inf, the fit routine
     |      will throw a RuntimeError.
     |      
     |      When the location is fixed by using the argument `floc`, this
     |      function uses explicit formulas or solves a simpler numerical
     |      problem than the full ML optimization problem.  So in that case,
     |      the `optimizer`, `loc` and `scale` arguments are ignored.
     |      
     |      Examples
     |      --------
     |      
     |      Generate some data to fit: draw random variates from the `beta`
     |      distribution
     |      
     |      >>> from scipy.stats import beta
     |      >>> a, b = 1., 2.
     |      >>> x = beta.rvs(a, b, size=1000)
     |      
     |      Now we can fit all four parameters (``a``, ``b``, ``loc`` and ``scale``):
     |      
     |      >>> a1, b1, loc1, scale1 = beta.fit(x)
     |      
     |      We can also use some prior knowledge about the dataset: let's keep
     |      ``loc`` and ``scale`` fixed:
     |      
     |      >>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
     |      >>> loc1, scale1
     |      (0, 1)
     |      
     |      We can also keep shape parameters fixed by using ``f``-keywords. To
     |      keep the zero-th shape parameter ``a`` equal 1, use ``f0=1`` or,
     |      equivalently, ``fa=1``:
     |      
     |      >>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
     |      >>> a1
     |      1
     |      
     |      Not all distributions return estimates for the shape parameters.
     |      ``norm`` for example just returns estimates for location and scale:
     |      
     |      >>> from scipy.stats import norm
     |      >>> x = norm.rvs(a, b, size=1000, random_state=123)
     |      >>> loc1, scale1 = norm.fit(x)
     |      >>> loc1, scale1
     |      (0.92087172783841631, 2.0015750750324668)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from scipy.stats._distn_infrastructure.rv_continuous:
     |  
     |  __init__(self, momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  cdf(self, x, *args, **kwds)
     |      Cumulative distribution function of the given RV.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      cdf : ndarray
     |          Cumulative distribution function evaluated at `x`
     |  
     |  expect(self, func=None, args=(), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)
     |      Calculate expected value of a function with respect to the
     |      distribution by numerical integration.
     |      
     |      The expected value of a function ``f(x)`` with respect to a
     |      distribution ``dist`` is defined as::
     |      
     |                  ub
     |          E[f(x)] = Integral(f(x) * dist.pdf(x)),
     |                  lb
     |      
     |      where ``ub`` and ``lb`` are arguments and ``x`` has the ``dist.pdf(x)``
     |      distribution. If the bounds ``lb`` and ``ub`` correspond to the
     |      support of the distribution, e.g. ``[-inf, inf]`` in the default
     |      case, then the integral is the unrestricted expectation of ``f(x)``.
     |      Also, the function ``f(x)`` may be defined such that ``f(x)`` is ``0``
     |      outside a finite interval in which case the expectation is
     |      calculated within the finite range ``[lb, ub]``.
     |      
     |      Parameters
     |      ----------
     |      func : callable, optional
     |          Function for which integral is calculated. Takes only one argument.
     |          The default is the identity mapping f(x) = x.
     |      args : tuple, optional
     |          Shape parameters of the distribution.
     |      loc : float, optional
     |          Location parameter (default=0).
     |      scale : float, optional
     |          Scale parameter (default=1).
     |      lb, ub : scalar, optional
     |          Lower and upper bound for integration. Default is set to the
     |          support of the distribution.
     |      conditional : bool, optional
     |          If True, the integral is corrected by the conditional probability
     |          of the integration interval.  The return value is the expectation
     |          of the function, conditional on being in the given interval.
     |          Default is False.
     |      
     |      Additional keyword arguments are passed to the integration routine.
     |      
     |      Returns
     |      -------
     |      expect : float
     |          The calculated expected value.
     |      
     |      Notes
     |      -----
     |      The integration behavior of this function is inherited from
     |      `scipy.integrate.quad`. Neither this function nor
     |      `scipy.integrate.quad` can verify whether the integral exists or is
     |      finite. For example ``cauchy(0).mean()`` returns ``np.nan`` and
     |      ``cauchy(0).expect()`` returns ``0.0``.
     |      
     |      Examples
     |      --------
     |      
     |      To understand the effect of the bounds of integration consider
     |      
     |      >>> from scipy.stats import expon
     |      >>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
     |      0.6321205588285578
     |      
     |      This is close to
     |      
     |      >>> expon(1).cdf(2.0) - expon(1).cdf(0.0)
     |      0.6321205588285577
     |      
     |      If ``conditional=True``
     |      
     |      >>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
     |      1.0000000000000002
     |      
     |      The slight deviation from 1 is due to numerical integration.
     |  
     |  fit_loc_scale(self, data, *args)
     |      Estimate loc and scale parameters from data using 1st and 2nd moments.
     |      
     |      Parameters
     |      ----------
     |      data : array_like
     |          Data to fit.
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      
     |      Returns
     |      -------
     |      Lhat : float
     |          Estimated location parameter for the data.
     |      Shat : float
     |          Estimated scale parameter for the data.
     |  
     |  isf(self, q, *args, **kwds)
     |      Inverse survival function (inverse of `sf`) at q of the given RV.
     |      
     |      Parameters
     |      ----------
     |      q : array_like
     |          upper tail probability
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      x : ndarray or scalar
     |          Quantile corresponding to the upper tail probability q.
     |  
     |  logcdf(self, x, *args, **kwds)
     |      Log of the cumulative distribution function at x of the given RV.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      logcdf : array_like
     |          Log of the cumulative distribution function evaluated at x
     |  
     |  logpdf(self, x, *args, **kwds)
     |      Log of the probability density function at x of the given RV.
     |      
     |      This uses a more numerically accurate calculation if available.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      logpdf : array_like
     |          Log of the probability density function evaluated at x
     |  
     |  logsf(self, x, *args, **kwds)
     |      Log of the survival function of the given RV.
     |      
     |      Returns the log of the "survival function," defined as (1 - `cdf`),
     |      evaluated at `x`.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      logsf : ndarray
     |          Log of the survival function evaluated at `x`.
     |  
     |  nnlf(self, theta, x)
     |      Return negative loglikelihood function.
     |      
     |      Notes
     |      -----
     |      This is ``-sum(log pdf(x, theta), axis=0)`` where `theta` are the
     |      parameters (including loc and scale).
     |  
     |  pdf(self, x, *args, **kwds)
     |      Probability density function at x of the given RV.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      pdf : ndarray
     |          Probability density function evaluated at x
     |  
     |  ppf(self, q, *args, **kwds)
     |      Percent point function (inverse of `cdf`) at q of the given RV.
     |      
     |      Parameters
     |      ----------
     |      q : array_like
     |          lower tail probability
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      x : array_like
     |          quantile corresponding to the lower tail probability q.
     |  
     |  sf(self, x, *args, **kwds)
     |      Survival function (1 - `cdf`) at x of the given RV.
     |      
     |      Parameters
     |      ----------
     |      x : array_like
     |          quantiles
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      sf : array_like
     |          Survival function evaluated at x
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from scipy.stats._distn_infrastructure.rv_generic:
     |  
     |  __call__(self, *args, **kwds)
     |      Freeze the distribution for the given arguments.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution.  Should include all
     |          the non-optional arguments, may include ``loc`` and ``scale``.
     |      
     |      Returns
     |      -------
     |      rv_frozen : rv_frozen instance
     |          The frozen distribution.
     |  
     |  __getstate__(self)
     |  
     |  __setstate__(self, state)
     |  
     |  entropy(self, *args, **kwds)
     |      Differential entropy of the RV.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      loc : array_like, optional
     |          Location parameter (default=0).
     |      scale : array_like, optional  (continuous distributions only).
     |          Scale parameter (default=1).
     |      
     |      Notes
     |      -----
     |      Entropy is defined base `e`:
     |      
     |      >>> drv = rv_discrete(values=((0, 1), (0.5, 0.5)))
     |      >>> np.allclose(drv.entropy(), np.log(2.0))
     |      True
     |  
     |  freeze(self, *args, **kwds)
     |      Freeze the distribution for the given arguments.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution.  Should include all
     |          the non-optional arguments, may include ``loc`` and ``scale``.
     |      
     |      Returns
     |      -------
     |      rv_frozen : rv_frozen instance
     |          The frozen distribution.
     |  
     |  interval(self, alpha, *args, **kwds)
     |      Confidence interval with equal areas around the median.
     |      
     |      Parameters
     |      ----------
     |      alpha : array_like of float
     |          Probability that an rv will be drawn from the returned range.
     |          Each value should be in the range [0, 1].
     |      arg1, arg2, ... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      loc : array_like, optional
     |          location parameter, Default is 0.
     |      scale : array_like, optional
     |          scale parameter, Default is 1.
     |      
     |      Returns
     |      -------
     |      a, b : ndarray of float
     |          end-points of range that contain ``100 * alpha %`` of the rv's
     |          possible values.
     |  
     |  mean(self, *args, **kwds)
     |      Mean of the distribution.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      mean : float
     |          the mean of the distribution
     |  
     |  median(self, *args, **kwds)
     |      Median of the distribution.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          Location parameter, Default is 0.
     |      scale : array_like, optional
     |          Scale parameter, Default is 1.
     |      
     |      Returns
     |      -------
     |      median : float
     |          The median of the distribution.
     |      
     |      See Also
     |      --------
     |      rv_discrete.ppf
     |          Inverse of the CDF
     |  
     |  moment(self, n, *args, **kwds)
     |      n-th order non-central moment of distribution.
     |      
     |      Parameters
     |      ----------
     |      n : int, n >= 1
     |          Order of moment.
     |      arg1, arg2, arg3,... : float
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |  
     |  rvs(self, *args, **kwds)
     |      Random variates of given type.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      loc : array_like, optional
     |          Location parameter (default=0).
     |      scale : array_like, optional
     |          Scale parameter (default=1).
     |      size : int or tuple of ints, optional
     |          Defining number of random variates (default is 1).
     |      random_state : None or int or ``np.random.RandomState`` instance, optional
     |          If int or RandomState, use it for drawing the random variates.
     |          If None, rely on ``self.random_state``.
     |          Default is None.
     |      
     |      Returns
     |      -------
     |      rvs : ndarray or scalar
     |          Random variates of given `size`.
     |  
     |  stats(self, *args, **kwds)
     |      Some statistics of the given RV.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional (continuous RVs only)
     |          scale parameter (default=1)
     |      moments : str, optional
     |          composed of letters ['mvsk'] defining which moments to compute:
     |          'm' = mean,
     |          'v' = variance,
     |          's' = (Fisher's) skew,
     |          'k' = (Fisher's) kurtosis.
     |          (default is 'mv')
     |      
     |      Returns
     |      -------
     |      stats : sequence
     |          of requested moments.
     |  
     |  std(self, *args, **kwds)
     |      Standard deviation of the distribution.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      std : float
     |          standard deviation of the distribution
     |  
     |  support(self, *args, **kwargs)
     |      Return the support of the distribution.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, ... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information).
     |      loc : array_like, optional
     |          location parameter, Default is 0.
     |      scale : array_like, optional
     |          scale parameter, Default is 1.
     |      Returns
     |      -------
     |      a, b : float
     |          end-points of the distribution's support.
     |  
     |  var(self, *args, **kwds)
     |      Variance of the distribution.
     |      
     |      Parameters
     |      ----------
     |      arg1, arg2, arg3,... : array_like
     |          The shape parameter(s) for the distribution (see docstring of the
     |          instance object for more information)
     |      loc : array_like, optional
     |          location parameter (default=0)
     |      scale : array_like, optional
     |          scale parameter (default=1)
     |      
     |      Returns
     |      -------
     |      var : float
     |          the variance of the distribution
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from scipy.stats._distn_infrastructure.rv_generic:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  random_state
     |      Get or set the RandomState object for generating random variates.
     |      
     |      This can be either None or an existing RandomState object.
     |      
     |      If None (or np.random), use the RandomState singleton used by np.random.
     |      If already a RandomState instance, use it.
     |      If an int, use a new RandomState instance seeded with seed.
    


# Lognormal distribution


```
from scipy.stats import lognorm

data_lognorm = lognorm.rvs(0.2, size=10000)
ax = sns.distplot(data_lognorm,kde=False,
                  bins=100,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Log Normal', ylabel='Frequency');
```

# Negative Binomial distribution
* discrete


```
from scipy.stats import nbinom

data_nbinom = nbinom.rvs(10, 0.5, size=10000)
ax = sns.distplot(data_nbinom,
                  kde=False,
                  color='skyblue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Negative Binomial', ylabel='Frequency');
```

# PDF e CDF
PDF: Função Densidade de Probabilidade
* relativa
* não negativa
* integral = 1

CDF: Função Distribuição Acumulada
* acumulada
* não negativa
* integral = 1

Survivor fuction = 1 - CDF

ECDF
* estimador empírico



```

```

dfa44b0b863d5f6ce1ce4d42f8ec5257baa46ec9
ipynb
Jupyter Notebook
GoogleColab/AceleraDevEstatistica.ipynb
viniciusriosfuck/dscodenation
b59fb4417f6b348538f500123fe0ed4d048e2505
MIT
2020-11-09T18:18:41.000Z
2020-11-09T18:18:41.000Z
GoogleColab/AceleraDevEstatistica.ipynb
inaborges/dscodenation
710113aeed64f3302fe207201a967cc7cdc9e8e7
MIT
2020-07-21T17:28:07.000Z
2020-08-05T22:30:35.000Z
GoogleColab/AceleraDevEstatistica.ipynb
inaborges/dscodenation
710113aeed64f3302fe207201a967cc7cdc9e8e7
MIT
2020-07-21T22:40:33.000Z
2020-07-21T22:40:33.000Z
Qwen/Qwen-72B
1. YES
2. YES