text_plain_output_1.png image_output_1.png
from scipy.stats import bernoulli

from scipy.stats import beta

from scipy.stats import beta

from scipy.stats import binom

from scipy.stats import norm

from scipy.stats import norm

from scipy.stats import poisson

from scipy.stats import uniform

import seaborn as sns

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
sns.set(rc={'figure.figsize': (9.5, 5)})

# import uniform distribution
from scipy.stats import uniform

# generate random numbers from a uniform distribution
sample_size = 10000
param_loc = 5 # left-hand endpoint of the domain interval
param_scale = 10 # width of the domain interval
data_uniform = uniform.rvs(size=sample_size, loc=param_loc, scale=param_scale)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_uniform[0:5])

# plot a historgram of the output
ax = sns.distplot(data_uniform,
                  bins=100,
                  kde_kws={"label": "KDE"},
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Uniform Distribution: Sample Size = {sample_size}. loc={param_loc}, scale={param_scale}');

from scipy.stats import norm

# generate random numbers from a normal distribution

sample_size = 100
param_loc = 3 # mean
param_scale = 2 # standard deviation
data_normal = norm.rvs(size=sample_size,loc=param_loc,scale=param_scale)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_normal[0:5])

# plot a histogram of the output
ax = sns.distplot(data_normal,
                  bins=100,
                  kde_kws={"label": "KDE"},
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Normal Distribution: Sample Size = {sample_size}, loc={param_loc}, scale={param_scale}');

# import bernoulli
from scipy.stats import bernoulli

# generate bernoulli data
sample_size = 100000
param_p = 0.3 # probability of sucess
data_bern = bernoulli.rvs(size=sample_size,p=param_p)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_bern[0:5])

# Create the Plot
ax= sns.distplot(data_bern,                  
                  kde=False,
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Bernoulli Distribution: Sample Size = {sample_size}, p={param_p}');
ax.legend();

from scipy.stats import binom

# Generate Binomial Data
sample_size = 10000
param_n = 10 # number of trials
param_p = 0.7 # probability of success in one trial
data_binom = binom.rvs(size=sample_size, n=param_n,p=param_p,)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_binom[0:5])

# Create the Plot
ax = sns.distplot(data_binom,
                  kde=False,
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Binomial Distribution: n={param_n} ,p={param_p}')
ax.legend();

from scipy.stats import poisson

# Generate Poisson Data
sample_size = 10000
param_mu = 3 #(rate of events per time, often denoted lambda)
data_poisson = poisson.rvs(size=sample_size, mu=param_mu)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_poisson[0:5])

# Create the Plot
ax = sns.distplot(data_poisson,
                  kde=False,
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Poisson Distribution: Sample Size = {sample_size}, mu={param_mu}');
ax.legend();

from scipy.stats import beta

# Generate beta Data
sample_size = 100000
param_a = 1
param_b = 5
data_beta = beta.rvs(param_a, param_b, size=sample_size)

# print a few values from the distribution:
print('The first 5 values from this distribution:')
print(data_beta[0:5])

# Create the Plot
ax = sns.distplot(data_beta,
                  kde_kws={"label": "KDE"},
                  hist_kws={"label": "Histogram"})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Beta({param_a},{param_b}) Distribution: Sample Size = {sample_size}');
ax.legend();

from scipy.stats import beta
sample_size = 100000
param_a = 0.5
param_b = 0.5
data_beta = beta.rvs(param_a, param_b, size=sample_size)
print('The first 5 values from this distribution:')
print(data_beta[0:5])
ax = sns.distplot(data_beta, kde_kws={'label': 'KDE'}, hist_kws={'label': 'Histogram'})
ax.set(xlabel='x ', ylabel='Frequency', title=f'Beta({param_a},{param_b}) Distribution: Sample Size = {sample_size}')
ax.legend()