Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 딥러닝
- BLaST
- 블록체인
- 자바
- 서열정렬
- 파이썬
- AP
- 인공지능
- 인공신경망
- 캐글
- RNN
- COVID
- SVM
- 결정트리
- HMM
- 시그모이드
- Kaggle
- 이항분포
- 인공지능 수학
- 바이오파이썬
- 오류역전파
- 바이오인포매틱스
- AP Computer Science A
- ncbi
- 생명정보학
- Java
- MERS
- CNN
- bioinformatics
- 생물정보학
Archives
- Today
- Total
데이터 과학
파이썬 이항분포 본문
파이썬을 이용하여 이항분포를 표현할 수 있습니다.
numpy나 scipy 라이브러리를 사용해서 이항분포를 나타낼 수 있는데 Colab에서도 운영할 수 있습니다.
numpy에서 binomial 함수를 이용하여 n, p의 조건값과 그 결과를 나타낼 수 있습니다.
import numpy as np
n=30
p=0.5
np.random.binomial(n,p,size=10)
중심극한의 정리를 이용하여 이항분포를 평균은 np, 분산은 np(1-p) 로 정규분포와 같은 모양으로 표현할 수 있습니다.
import numpy as np
import matplotlib.pyplot as plt
n = 200
p = 0.5
size = 500
binom_sample = np.random.binomial(n, p, size)
normal_sample = n * p + np.sqrt(n * p * (1-p)) * np.random.randn(size)
plt.hist(binom_sample, color = 'blue', alpha = 0.3, bins = 25, label = 'binomial')
plt.hist(normal_sample, color = 'red', alpha = 0.4, bins = 25, label = 'normal')
plt.legend()
plt.show()
사이즈를 늘르면 샘플의 갯수가 늘어나기에 좀더 중심극한의 정리에 수렴합니다.
데이터의 갯수가 많으면 이항분포도 정규분포로 표현가능합니다.
import numpy as np
import matplotlib.pyplot as plt
n = 200
p = 0.5
size = 10000
binom_sample = np.random.binomial(n, p, size)
normal_sample = n * p + np.sqrt(n * p * (1-p)) * np.random.randn(size)
plt.hist(binom_sample, color = 'blue', alpha = 0.3, bins = 25, label = 'binomial')
plt.hist(normal_sample, color = 'red', alpha = 0.4, bins = 25, label = 'normal')
plt.legend()
plt.show()

레퍼런스: https://jimmy-ai.tistory.com/157
[Numpy] 파이썬 이항분포 표본 추출, 정규분포 근사 시각화 예제
np.random.binomial 함수 사용법과 중심 극한 정리 예시 파이썬 넘파이 라이브러리에서 이항분포를 따르는 표본을 추출하고, 반복 시행 표본의 결과가 정규분포와 가까워지는 것을 시각화해보는 예
jimmy-ai.tistory.com
https://datascienceschool.net/
https://datascienceschool.net/
datascienceschool.net
'AP > AP Statistics' 카테고리의 다른 글
| AP Statistics 시작 (0) | 2023.01.01 |
|---|---|
| 편향 Bias (0) | 2022.09.06 |
| 파이썬에서 정규분포 (0) | 2022.04.28 |
| 순열과 조합 - 이항분포 (2) | 2022.03.29 |
| 베이즈 정리 (0) | 2021.10.04 |