```
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats as st
```

## Univariate normal distribution

The normal distribution, also known as the **Gaussian distribution**, is so called because its based on the Gaussian function . This distribution is defined by two parameters: the **mean** $\mu$, which is the **expected value of the distribution**, and the **standard deviation** $\sigma$, which corresponds to the **expected deviation from the mean**. The square of the standard deviation is typically referred to as the **variance** $\sigma^2$. We denote this distribution as:

\begin{equation}
$\mathcal{N}=(\mu,\sigma)$
\end{equation}

Given this mean and variance we can calculate the **probility densitiy function** (**pdf**) of the normal distribution with the normalised Gaussian function. For a value $x$ the density is:

\begin{equation}
p(x \mid \mu, \sigma) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp{ \left( -\frac{(x - \mu)^2}{2\sigma^2}\right)}
\end{equation}

We call this distribution the **univariate** normal because it consists of **only one random normal variable**. Three examples of univariate normal distributions with different mean and variance are plotted in the next figure:


```
def univariate_normal(x, mean, std):
    """pdf of the univariate normal distribution."""
    return ((1. / np.sqrt(2 * np.pi * std**2)) * np.exp(-(x - mean)**2 / (2 * std**2)))
```


```
# Plot different Univariate Normals
x = np.linspace(-5, 5, num=150)
fig = plt.figure(figsize=(10, 5))
plt.plot(x, univariate_normal(x, mean=0, std=1),label="$\mathcal{N}(0, 1)$")
plt.xlabel('$x$', fontsize=13)
plt.ylabel('density: $p(x)$', fontsize=13)
plt.title('Univariate normal distributions')
plt.ylim([0, 1])
plt.xlim([-5, 5])
plt.legend(loc=1)

plt.show()
```


```
# Plot different Univariate Normals
x = np.linspace(-5, 5, num=150)
fig = plt.figure(figsize=(10, 7))
plt.plot(x, univariate_normal(x, mean=0, std=2),label="$\mathcal{N}(0, 2)$")
plt.plot(x, univariate_normal(x, mean=0, std=0.5),label="$\mathcal{N}(0, 0.5)$")
plt.plot(x, univariate_normal(x, mean=2, std=2),label="$\mathcal{N}(2, 2)$")
plt.plot(x, univariate_normal(x, mean=2, std=0.4),label="$\mathcal{N}(2, 0.4)$")
plt.xlabel('$x$', fontsize=13)
plt.ylabel('density: $p(x)$', fontsize=13)
plt.title('Univariate normal distributions')
plt.ylim([0, 1])
plt.xlim([-5, 5])
plt.legend(loc=1)

plt.show()
```


```
# Plot different Univariate Normals
x = np.linspace(-5, 5, num=150)
fig = plt.figure(figsize=(10, 7))
plt.plot(x, st.norm.pdf(x, loc=0, scale=1),label="$\mathcal{N}(0, 1)$")
plt.plot(x, st.norm.pdf(x, loc=2, scale=2),label="$\mathcal{N}(2, 3)$")
plt.plot(x, st.norm.pdf(x, loc=0, scale=0.5),label="$\mathcal{N}(0, 0.2)$")
plt.xlabel('$x$', fontsize=13)
plt.ylabel('density: $p(x)$', fontsize=13)
plt.title('Univariate normal distributions')
plt.ylim([0, 1])
plt.xlim([-5, 5])
plt.legend(loc=1)
plt.show()


```

2a620affd322b47130ea660592f631405dbf3d6f
ipynb
Jupyter Notebook
L06_gaussian distribuition/L06_1D gaussian.ipynb
pedrogomes-dev/MA28CP-Intro-to-Machine-Learning
fd24017b8195a0d9ec9511071d4f8842dd596861
MIT
2020-08-24T20:23:24.000Z
2022-03-17T13:47:59.000Z
L06_gaussian distribuition/L06_1D gaussian.ipynb
pedrogomes-dev/MA28CP-Intro-to-Machine-Learning
fd24017b8195a0d9ec9511071d4f8842dd596861
MIT
L06_gaussian distribuition/L06_1D gaussian.ipynb
pedrogomes-dev/MA28CP-Intro-to-Machine-Learning
fd24017b8195a0d9ec9511071d4f8842dd596861
MIT
2020-08-29T14:30:40.000Z
2022-03-24T13:42:17.000Z
Qwen/Qwen-72B
1. YES
2. YES