Python 機率基礎
Alexander A. Ramírez M.
CEO @ Synergy Vision
$$ $$

在 Python 中,只要幾行就能完成:
# Import norm
from scipy.stats import norm
# 用 pdf 計算機率密度 norm.pdf(-1, loc=0, scale=1)0.24197072451914337
參數 loc 指定平均數,scale 指定標準差。
$$ $$

$$ $$

$$ $$

$$ $$

$$ $$

$$ $$


# 計算 -1 的 cdf
norm.cdf(-1)
0.15865525393145707

# 計算 0.5 的 cdf
norm.cdf(0.5)
0.6914624612740131

# 計算 0.2 的 ppf
norm.ppf(0.2)
-0.8416212335729142

# 計算 55% 的 ppf
norm.ppf(0.55)
0.12566134685507416

# 計算值 0 的 cdf
norm.cdf(0)
0.5

# 計算機率 50% 的 ppf
norm.ppf(0.5)
0
$$ $$

$$ $$
# 建立變數 a = -1 b = 1 # 用相減計算兩值間的機率 norm.cdf(b) - norm.cdf(a)0.6826894921370859
$$ $$

$$ $$
# 建立變數 a = 1 # 用 sf() 計算 cdf() 的補集 norm.sf(a)0.15865525393145707
$$ $$

$$ $$
# 建立變數 a = -2 b = 2 # 將兩端相加計算尾端機率 norm.cdf(a) + norm.sf(b)0.04550026389635839
$$ $$

$$ $$
# 建立變數
a = -2
b = 2
# 將兩端相加計算尾端機率 norm.cdf(a) + norm.sf(b)0.04550026389635839
$$ $$

$$ $$
# 建立變數
alpha = 0.95
# 計算區間
norm.interval(alpha)
(-1.959963984540054, 1.959963984540054)
Python 機率基礎