<jupyter_start><jupyter_text>Probability Distribution in DS<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Bernoulli Distribution<jupyter_code># p = probability of success
# size = numbere of experiements
# rvs = random variables 
bern = stats.bernoulli.rvs(size = 10000, p = 0.5)
sns.distplot(bern, kde = False)
plt.title("Bernoulli Distribution")
plt.xlabel("Bernoulli Distribution")
plt.ylabel("Frequency")
# p = probability of success
# size = numbere of experiements
# rvs = random variables 
bern = stats.bernoulli.rvs(size = 10000, p = 0.7)
sns.distplot(bern, kde = False)
plt.title("Bernoulli Distribution")
plt.xlabel("Bernoulli Distribution")
plt.ylabel("Frequency")<jupyter_output><empty_output><jupyter_text>Uniform Distribution a possibly unlimited number of outcomes are allowed and all the events hold the same probability to take place. As an example, imagine the roll of a fair dice. In this case, there are multiple possible events which each of them having the same probability to happen.<jupyter_code># size = number of experiements
# loc = starting point
# scale = end point

uniform = stats.uniform.rvs(size = 100, loc = 0, scale = 6)
sns.distplot(uniform, kde = True)<jupyter_output>/home/nix-code/virtualenv/venv/lib/python3.8/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)<jupyter_text>Here is the distribution obtained when we roll a dice 100 times  Fair Dice uniform Distribution<jupyter_code>prob = np.full((6),1/6)
ch = np.arange(1,7) # ch is choice
plt.bar(ch, prob)
plt.title("Fair Dice uniform Distribution")
plt.xlabel("Choices")
plt.ylabel("Pribability")
ax = plt.gca()
ax.set_ylim([0,1])<jupyter_output><empty_output><jupyter_text>Loaded dice with non uniform distribution<jupyter_code>sampl = np.random.uniform(low=0, high=0.9, size=(6,))
face = [1,2,3,4,5,6]
plt.bar(face, sampl)
axes = plt.gca()
axes.set_ylim([0,1])<jupyter_output><empty_output><jupyter_text>Binomial Distribution The Binomial Distribution can instead be thought as the sum of outcomes of an event following a Bernoulli distribution. The Binomial Distribution is therefore used in binary outcome events and the probability of success and failure is the same in all the successive trials<jupyter_code># p is the probability that one of the events is going to take place
binom = stats.binom.rvs(size = 10000, n=10,p=0.5,random_state = 0)
pd.Series(binom).plot(kind='hist',bins=50)<jupyter_output><empty_output><jupyter_text>Given multiple trials, each of them is independent of each other (the outcome of one trial doesn't affect another one).Each trial can lead to just two possible results (eg. winning or losing), which have probabilities p and (1 - p).  Change the probability value to see the distribution , as the trials is independent, we may see diff distribution<jupyter_code>for i in range(3,10,3):
    bi = stats.binom.rvs(size = 10000, n=10, p = 0.1*i, random_state = 42)
    pd.Series(bi).plot(kind='hist',bins=20, label="p = {:f}".format(0.1*i))
    plt.xlabel("Random Variable")
    plt.ylabel("Frequency")
    plt.title("Binomial distribution for varying p")
    plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10441426146010187, 'fraction_numerical': 0.022354272778720995, 'mean_word_length': 5.785028790786948, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '377920', 'license': 'MIT', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1117, 'n_words': 368, 'path': 'Intermediate Probability Distribution.ipynb', 'repo_name': 'Nix-code/statistics-for-data-science', 'size': '3534'}