<jupyter_start><jupyter_text>Gaussian / Normal Distribution  f(x) = $\frac{1}{\sqrt{2\pi	\sigma^2}} e^ \frac{-(x-\mu)^2}{2\sigma^2}$    When the normal distribution has a mean () of zero and standard deviation () of one, as it does by default with the NumPy normal() method, it is a standard normal distribution (a.k.a., standard Gaussian distribution or z-distribution).<jupyter_code># create random data points of a normal distribution
normal_dist = np.random.normal(size=5000)

# plot the distribution
sns.distplot(normal_dist)<jupyter_output><empty_output><jupyter_text>Uses approximate distributions in arrays to stand for Random Variables<jupyter_code>mean = 0
var = 1

X = np.random.normal(2, math.sqrt(var), 100000)
Y =  2*X + 3

plt.figure(figsize=(8, 3))
plt.title('Approx Normal PDF Before and After Transformation', fontsize=16)
plt.ylabel('density', fontsize=14)
plt.xlabel('x', fontsize=14)
sns.kdeplot(X, shade=True, label='X', color='red')
sns.kdeplot(Y, shade=True, label='Y = 2X + 3', lw=3, color='purple')
plt.xlim(-15, 30)
plt.legend(fontsize=14)

plt.show()

table = pd.DataFrame({'X':[mean, var], 'Y':[round(np.mean(Y), 2), round(np.var(Y), 2)]})
table.rename(index={0:'mean', 1:'variance'}, inplace=True)
print(table)<jupyter_output><empty_output><jupyter_text>Normal distribution CDF Plot simulation<jupyter_code>mu = 5
variance = 1
sigma = math.sqrt(variance)
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)
plt.plot(x, scipy.stats.norm.cdf(x, mu, sigma))
plt.show()<jupyter_output><empty_output><jupyter_text>The Central Limit TheoremWith large enough sample sizes, we can assume the sampling* distribution of the means will be normally distributed.*Sampling from any distribution<jupyter_code># function for generating sampling distributions

def sample_mean_calculator(input_dist, sample_size, n_samples):
    sample_means = []
    for i in range(n_samples):
        sample = np.random.choice(input_dist, size=sample_size, replace=False)
        sample_means.append(sample.mean())
        
    return sample_means<jupyter_output><empty_output><jupyter_text>Sampling from skewed distribution<jupyter_code># create a skewed distribution as example
sk_dist = s = scipy.stats.skewnorm.rvs(10, size=10000)

# plot the distribution
sns.displot(s, kde=True)
# plot the distribution of the sample means
sns.displot(sample_mean_calculator(sk_dist, 10, 10), color='green', kde=True)<jupyter_output><empty_output><jupyter_text>The more samples we take, the more likely that the sampling distribution of the means will be normally distributed.<jupyter_code>sns.displot(sample_mean_calculator(sk_dist, 10, 100), color='green', kde=True)<jupyter_output><empty_output><jupyter_text>The larger the sample, the tighter the sample means will tend to be around the population mean...<jupyter_code>sns.displot(sample_mean_calculator(sk_dist, 1000, 1000), color='green', kde=True)<jupyter_output><empty_output><jupyter_text>Sampling from uniform distribution<jupyter_code>unif_dist = np.random.uniform(size=10000)

sns.displot(unif_dist)
_ = sns.displot(sample_mean_calculator(unif_dist, 1000, 1000), color='red', kde=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12749130022144892, 'fraction_numerical': 0.027206580196140463, 'mean_word_length': 6.788177339901478, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '595946', 'license': 'MIT', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1066, 'n_words': 263, 'path': 'Lecture 2 - Probability Redux.ipynb', 'repo_name': 'CarolGonz/fundamentals_of_statistics_mitx', 'size': '3161'}