<< 3주차 Lecture Note 2번째>>
- Bootstrapping
- simple method
Bootstrapping
2024.05.14 - [KOOC/DataScience Programming] - Confidence Interval and Bootstraping <3-1>
Confidence Interval and Bootstraping <3-1>
>Sample and PopulationCentral Limit TheoremSample and Population 앞선 강의에서 데이터로부터 moment를 구한 후 fit한 분포를 찾는 것을 배웠다.이 때 구한 moment는 결국 분포의 파라미터와 연관되어 있는데,문제
statfinance.tistory.com
앞 글에서 전체 30,000개의 데이터 중 10,000개 씩 추출 후 sample mean을 계산하는 과정을 3,000번 반복했다.
그리고 그 sample mean에 CLT(중심극한정리)이 적용됨으로써 가우시안(또는 정규분포)를 따르게 되며, CI를 구할 수 있게 됐다.
Bootstrapping 이란,
한정된 데이터 내에서 샘플을 반복적으로 복원 추출하는 것을 말한다.
즉, 위에서 설명한 CI를 구하기 위한 과정의 방법론이다.
현재 우리의 궁극적인 목적은 주어진 데이터를 특정 분포에 fit 하는 것이다.
이를 위해 bootstrapping 방법론을 이용해 CLT를 적용하도록 무수한 수의 샘플 파라미터를 구하고,
이로부터 CI 산출 및 파라미터 검증을 완료함으로써 목적을 달성할 수 있는 것이다.
simple method
Bootstrapping을 위한 간단한 메서드 코드는 아래와 같다.
def getBootstrapSamples(objSeries: pd.Series, intSampleNum: int):
lstSample = []
for _ in range(intSampleNum):
intRandomIdx = random.randrange(0, len(objSeries))
lstSample.append(objSeries[intRandomIdx])
return lstSample
위 코드는 시리즈 데이터에서 지정한 갯수만큼을 random하게 추출하는 메서드이다.
intRandomIdx를 random하게 추출 후 그 인덱스에 해당하는 시리즈 데이터를 가져와 lstSample 에 추가한다.
이런 식으로 복원 추출 된 부트스트랩 데이터의 sample mean에 대한 분포를 그려보면,
CLT에 의해 정규분포 형태를 따르게 된다.
'KOOC > DataScience Programming' 카테고리의 다른 글
Linear Regression Basic <5-1> (0) | 2024.05.22 |
---|---|
Multivariate Gaussian Distribution and Covariance<4-1> (1) | 2024.05.19 |
Confidence Interval and Bootstrapping <3-1> (0) | 2024.05.14 |
Distribution and Parameter Inference <2-1> (0) | 2024.05.13 |
Data Handling and Descriptive Statistics <1-2> (0) | 2024.04.29 |