加總隨機變數

Python 機率基礎

Alexander A. Ramírez M.

CEO @ Synergy Vision

中央極限定理(CLT)

當隨機變數的數量趨近無限大時,其總和會趨近常態分佈。

條件:

  • 變數須具相同分佈。
  • 變數須彼此獨立。
Python 機率基礎

Poisson 分佈的樣本生成動畫

Python 機率基礎

從樣本圖中隨機抽取

Python 機率基礎

從母體隨機抽樣的示意

Python 機率基礎

樣本平均的計算與長條圖

Python 機率基礎

Poisson 母體圖

# Add the imports
from scipy.stats import poisson, describe
from matplotlib import pyplot as plt
import numpy as np
# Generate the population
population = poisson.rvs(mu=2, size=1000, random_state=20)
# Draw the histogram with labels
plt.hist(population, bins=range(9), width=0.8)
plt.show()
Python 機率基礎

Poisson 母體長條圖

Python 機率基礎

樣本平均繪圖

# Generate 350 sample means, selecting
# from population values
np.random.seed(42)

# Define list of sample means
sample_means = []
for _ in range(350):
    # Select 10 from population
    sample = np.random.choice(population, 10)
    # Calculate sample mean of sample
    sample_means.append(describe(sample).mean)
Python 機率基礎

樣本平均繪圖(續)

$$ $$

# Draw histogram with labels
plt.xlabel("Sample mean values")
plt.ylabel("Frequency")
plt.title("Sample means histogram")
plt.hist(sample_means)
plt.show()

鐘形的樣本平均長條圖

Python 機率基礎

一起來加總隨機變數

Python 機率基礎

Preparing Video For Download...