<jupyter_start><jupyter_text>`Probability Distributions`<jupyter_code>%matplotlib inline 
# for inline plots in jupyter
import matplotlib.pyplot as plt# import matplotlib
import seaborn as sns
import warnings
warnings.simplefilter("ignore")
from ipywidgets import interact
styles = ['seaborn-notebook', 'seaborn', 'seaborn-darkgrid', 'classic', 
          '_classic_test', 'seaborn-poster', 'tableau-colorblind10', 'grayscale', 
          'fivethirtyeight', 'seaborn-ticks', 'seaborn-dark', 
          'dark_background', 'seaborn-pastel', 
          'fast', 'Solarize_Light2', 'seaborn-colorblind', 'seaborn-white',
          'seaborn-dark-palette',
          'bmh', 'seaborn-talk', 'seaborn-paper', 'seaborn-deep', 'seaborn-bright', 
          'seaborn-muted', 
          'seaborn-whitegrid', 'ggplot']<jupyter_output><empty_output><jupyter_text>`3. Bernoulli Distribution`A random variable X is said to be a Bernoulli random variable with parameter p, shown as X∼Bernoulli(p), if its PMF is given by\begin{equation}             \nonumber P_X(x) = \left\{              \begin{array}{l l}                 p& \quad \text{for  } x=1\\                1-p & \quad \text{ for } x=0\\                0  & \quad \text{ otherwise}              \end{array} \right.            \end{equation}            where 0<p<1.![](http://probabilitycourse.com/images/chapter3/bernoulli(p)%20color.png)<jupyter_code># import bernoulli
from scipy.stats import bernoulli<jupyter_output><empty_output><jupyter_text>* Bernoulli random variable can take either 0 or 1 using certain probability as a parameter. To generate 10000, bernoulli random numbers with success probability p =0.3, we will use bernoulli.rvs with two arguments.<jupyter_code># generate bernoulli
data_bern = bernoulli.rvs(size=10000,p=0.3)
ax= sns.distplot(data_bern,
                 kde=False,
                 hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Bernoulli', ylabel='Frequency')
# We can see from the plot below out of 10000 trials with success probability 0.3, 
# we get about 3000 successes
def BernoulliDistribution(palette="dark",kde = False,style = "ggplot"):
    plt.figure(figsize=(13,10))
    plt.style.use(style)
    sns.set_palette(palette)
    ax= sns.distplot(data_bern,
                 kde=kde,
                 hist_kws={"linewidth": 15,'alpha':1})
    ax.set(xlabel='Bernoulli', ylabel='Frequency')
    plt.show()
interact(BernoulliDistribution,palette = ["deep", "muted", "pastel", "bright", 
                    "dark", "colorblind","Set3","Set2"],kde = [True,False],style = styles);<jupyter_output><empty_output><jupyter_text>`4. Binomial Distribution`1. The binomial distribution is a discrete probability distribution that gives the probability that n identical independently distributed Bernoulli trials sum to k, where n is any natural number.![](https://www.s-cool.co.uk/gifs/a-mat-sdisc-dia08.gif)<jupyter_code>from scipy.stats import binom<jupyter_output><empty_output><jupyter_text>* Binomial distribution is a discrete probability distributionlike Bernoulli. It can be used to obtain the number of successes from N Bernoulli trials. For example, to find the number of successes in 10 Bernoulli trials with p =0.5, we will use<jupyter_code>binom.rvs(n=10,p=0.5)<jupyter_output><empty_output><jupyter_text>* We can also use binom.rvs to repeat the trials with size argument. If we want to repeat 5 times, we will use<jupyter_code>data_binom = binom.rvs(n=10,p=0.5,size=10000)
ax = sns.distplot(data_binom,
                  kde=False,
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Binomial', ylabel='Frequency')
def BinomialDistribution(palette="dark",kde = False,style = "ggplot"):
    plt.figure(figsize=(13,10))
    plt.style.use(style)
    sns.set_palette(palette)
    ax = sns.distplot(data_binom,
                  kde=kde,
                  hist_kws={"linewidth": 15,'alpha':1})
    ax.set(xlabel='Binomial', ylabel='Frequency')
    plt.show()
interact(BinomialDistribution,palette = ["deep", "muted", "pastel", "bright", 
                    "dark", "colorblind","Set3","Set2"],kde = [True,False],style = styles);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13112391930835735, 'fraction_numerical': 0.020653218059558116, 'mean_word_length': 3.7928653624856157, 'pattern_counts': {'":': 4, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '504291', 'license': 'MIT', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1368, 'n_words': 321, 'path': 'DataScience365/Day-13/Probability Distributions part-2.ipynb', 'repo_name': 'HiteshGorana/DataScience365', 'size': '4164'}