Standard/normal distribution (python implementation)

Standard/normal distribution (python implementation)

Normal Distribution (Normal Distribution), also known as Gaussian Distribution (Gaussian Distribution), is one of the most important probability distributions in probability theory and statistics. The probability density function of the normal distribution has the shape of a bell curve, exhibiting symmetry.

normal distribution

The normal distribution is fully determined by two parameters:

  • μ \muμ (mean): determines the center position of the curve
  • σ \sigma σ (standard deviation): determines the width of the curve or the dispersion of the distribution

Specifically, if a random variable XXX obeys normal distributionN ( μ , σ 2 ) N(\mu,\sigma ^2)N ( μ ,p2 ), then its probability density function is:
f ( x ) = 1 σ 2 π exp ⁡ ( − ( x − μ ) 2 2 σ 2 ) f(x)=\frac{1}{\sigma\sqrt{2 \pi}}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)f(x)=p2 p.m 1exp(2 p2(xm )2)

Among them, exp expe x p represents the exponential function of natural logarithm,π \piπ stands for pi.

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

mu = 50  # 均值
sigma = 10  # 标准差

# 生成正态分布随机数
samples_normal = np.random.normal(mu, sigma, 10000)

# 绘制正态分布的概率密度函数图形
x_normal = np.linspace(0, 100, 500)  # x轴范围
y_normal = norm.pdf(x_normal, mu, sigma)  # 计算概率密度函数值

# 绘制直方图: 箱子数 概率密度 透明度
plt.hist(samples_normal, bins=50, density=True, alpha=0.5, label='Generated Samples')
plt.plot(x_normal, y_normal, color='red', label='PDF')
plt.xlabel('x')
plt.ylabel('Probability Density')
plt.title('Normal Distribution')
plt.legend()
plt.show()

standard normal distribution

Standard Normal Distribution (Standard Normal Distribution) is a special form of normal distribution, with a mean of 0 and a standard deviation of 1. Its probability density function is recorded as φ ( z ) \varphi(z)φ ( z ) , wherezzz represents a standard normal random variable. And the curve has a peak value at the mean value of 0, and is symmetrical to the mean value.

There is a conversion relationship between the normal distribution and the standard normal distribution; standardization refers to the original normal distribution random variable XXX is converted to a standard normal distribution random variableZZZ
Z = X − μ σ Z = \frac {X - \mu} {\sigma} Z=pXm

Among them, ZZZ represents a standardized random variable,XXX represents the original normal distribution random variable,μ \muµσ \sigmaσ denote the mean and standard deviation of the original normal distribution, respectively.

The standard normal distribution has important applications in statistical inference and hypothesis testing because many statistical methods are based on properties of the standard normal distribution for calculation and derivation. Common statistical inference methods, such as ZZZ test andttThe t -test depends on the standard normal distribution.

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

# 标准正态分布
samples_standard_normal = np.random.standard_normal(10000)

# 绘制标准正态分布的概率密度函数图形
x_standard_normal = np.linspace(-10, 10, 500)  # x轴范围
y_standard_normal = norm.pdf(x_standard_normal, 0, 1)  # 计算概率密度函数值

plt.hist(samples_standard_normal, bins=50, density=True, alpha=0.5, label='Generated Samples')
plt.plot(x_standard_normal, y_standard_normal, color='red', label='PDF')
plt.xlabel('x')
plt.ylabel('Probability Density')
plt.title('Normal Distribution')
plt.legend()
plt.show()

Guess you like

Origin blog.csdn.net/m0_70885101/article/details/131471165