<jupyter_start><jupyter_text>Chapter02  1 Discrete random variable  1.1 (0-1) distribution$P(X=k)=p^k(1-p)^{1-k}, k=0,1 \space (0<p<1)$  1.2 binomial distribution$P(X=k)=C_n^kp^k(1-p)^{n-k}, \space k=0,1,\ldots,n \space (0<p<1)$   Marked as $X \sim B(n,p)$  1.3 possion Distribution$P(X=k)=\frac{\lambda^k e^{-\lambda}}{k!} \space \lambda > 0,\space k=0,1,2,\ldots$.   Marked as $X\sim \pi(\lambda)$***If  $X \sim B(n,p)$ and $n$ is big enough and $p$ is small enough, then: $$P(X=k)=C_n^kp^k(1-p)^{n-k} \approx \frac{\lambda^k e^{-\lambda}}{k!} $$ where: $\lambda=np$  1.4 geometric distribution$P(X=k)=(1-p)^{k-1}p, \space k=1,2,3,\dots$  2 Continues random variables  2.1 uniform distribution$$f(x)=\begin{cases}\frac{1}{b-a}, a<x<b \\0, others\end{cases}$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
plt.plot([1,2], [1,1], linewidth=2,c='k')
plt.plot([1,1], [0,1],'k--', linewidth=2)
plt.plot([2,2], [0,1],'k--', linewidth=2)
plt.plot([0,1], [1,1],'k--')
plt.xticks([1,2],[r'$a$',r'$b$'])
plt.yticks([1],[r'$\frac{1}{b-a}$'])
plt.xlabel('x')
plt.ylabel(r'$f(x)$')
plt.axis([0, 2.5, 0, 2])
gca = plt.gca()
gca.spines['right'].set_color('none')
gca.spines['top'].set_color('none')
gca.xaxis.set_ticks_position('bottom')
gca.yaxis.set_ticks_position('left')
plt.show()<jupyter_output><empty_output><jupyter_text>2.2 exponential distribution$$f(x)=\begin{cases}\lambda e^{-\lambda x}, x >0 \\0, x \le 0\end{cases}$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
lam = 5
x = np.linspace(0.01, 1, 1000)
f_x = lam * np.power(np.e, -1.0*lam*x)
plt.plot(x, f_x)
plt.xlabel('x')
plt.ylabel(r'$f(x)$')
plt.axis([0, 1.1, 0, 2])
plt.xticks(())
plt.yticks(())
gca = plt.gca()
gca.spines['right'].set_color('none')
gca.spines['top'].set_color('none')
gca.xaxis.set_ticks_position('bottom')
gca.yaxis.set_ticks_position('left')
plt.show()<jupyter_output><empty_output><jupyter_text>2.3 normal distribution$$f(x)=\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(x-\mu)^{2}}{2\sigma^2}}$$where: $-\infty < x < \infty$<jupyter_code>import math
import numpy as np
import matplotlib.pyplot as plt
def gauss(x, mu, sigma):
    return 1.0 / (np.sqrt(2*np.pi) * sigma) * np.power(np.e, -1.0 * np.power(x-1, 2)/ (2))
mu = 1.0
sigma = 1.0
x = np.linspace(-2.0, 4.0, 1000)
y = gauss(x, mu, sigma)
plt.plot(x, y)
plt.xticks([1.0], [r'$\mu$'])
plt.yticks(())
plt.xlabel('x')
plt.plot([1.0, 1.0],[0.0, gauss(1.0, mu, sigma)], 'k--')
plt.plot([0,1.0],[gauss(1.0, mu, sigma),gauss(1.0, mu, sigma)],'k--')
plt.text(0-.2, gauss(1.0, mu, sigma), r'$\frac{1}{\sqrt{2\pi}}$',ha='right', va='center')
plt.axis([-3,5,0,0.5])
#plt.(r'$\frac{1}{\sqrt{2\pi}}e^{-\frac{(x-1)^{2}}{2\sigma^2}}$')
gca = plt.gca()
gca.spines['right'].set_color('none')
gca.spines['top'].set_color('none')
gca.xaxis.set_ticks_position('bottom')
gca.spines['bottom'].set_position(('data',0))
gca.yaxis.set_ticks_position('left')
gca.spines['left'].set_position(('data',0))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2758389261744966, 'fraction_numerical': 0.05067114093959731, 'mean_word_length': 5.698876404494382, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '119223', 'license': 'MIT', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1383, 'n_words': 220, 'path': 'Probability-Theory/Chapter_02.ipynb', 'repo_name': 'gaufung/Data_Analytics_Learning_Note', 'size': '2980'}