표본평균에서 모평균으로

Python으로 배우는 확률 기초

Alexander A. Ramírez M.

CEO @ Synergy Vision

표본평균 복습

$$ $$

대수의 법칙

표본평균은 표본 크기가 커질수록 기댓값에 수렴합니다.

야코프 베르누이 우표

Python으로 배우는 확률 기초

표본평균 복습 (계속)

$$ \text{표본평균} = \bar{X_2} = \frac{x_1+x_2}{2} $$

Python으로 배우는 확률 기초

표본평균 복습 (계속)

$$ \text{표본평균} = \bar{X_3} = \frac{x_1+x_2+x_3}{3} $$

Python으로 배우는 확률 기초

표본평균 복습 (계속)

$$ \text{표본평균} = \bar{X_n} = \frac{x_1+x_2+\cdots +x_n}{n} $$

Python으로 배우는 확률 기초

표본평균 복습 (계속)

$$ \text{표본평균} = \bar{X_n} = \frac{x_1+x_2+\cdots +x_n}{n} \to \mathbb{E(X)} $$

Python으로 배우는 확률 기초

표본 생성하기

# Import binom and describe
from scipy.stats import binom
from scipy.stats import describe

# Sample of 250 fair coin flips
samples = binom.rvs(n=1, p=0.5, size=250, random_state=42)
# Print first 100 values from the sample
print(samples[0:100])
[0 1 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 0
 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 0 1
 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0]
Python으로 배우는 확률 기초

표본평균 계산하기

# Calculate the sample mean
print(describe(samples[0:10]).mean)
0.6
Python으로 배우는 확률 기초

표본평균의 기댓값 수렴

Python으로 배우는 확률 기초

표본평균 애니메이션: 기댓값으로 수렴

Python으로 배우는 확률 기초

표본평균 그리기

$$ $$

from scipy.stats import binom
from scipy.stats import describe
import matplotlib.pyplot as plt

# Define our variables
coin_flips, p, sample_size , averages = 1, 0.5, 1000, []
# Generate the sample
samples = binom.rvs(n=coin_flips, p=p, size=sample_size, random_state=42)
Python으로 배우는 확률 기초

표본평균 그리기 (계속)

$$ $$

# Calculate the sample mean
for i in range(2,sample_size+1):
    averages.append(describe(samples[0:i]).mean)

# Print the first values of averages
print(averages[0:10])
[0.5, 0.6666666666666666, 0.75, 0.6, 0.5, 0.42857142857142855, 0.5, 
0.5555555555555556,0.6, 0.5454545454545454]
Python으로 배우는 확률 기초

표본평균 그리기 (계속)

$$ $$

# Add population mean line and sample mean plot
plt.axhline(binom.mean(n=coin_flips, p=p), color='red')
plt.plot(averages, '-')
# Add legend
plt.legend(("모평균","표본평균"), loc='upper right')
plt.show()
Python으로 배우는 확률 기초

표본평균 그래프

표본평균 그래프

Python으로 배우는 확률 기초

연습해 봅시다!

Python으로 배우는 확률 기초

Preparing Video For Download...