Bootstrap Confidence Interval
Xem dạng PDF
Gửi bài giải
Điểm:
100,00
Giới hạn thời gian:
2.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python
Problem Statement
Given a dataset of n real numbers, estimate the 95% confidence interval for the population mean using the bootstrap method.
Algorithm:
- Draw
bbootstrap samples, each of sizen, sampling with replacement from the original data. - Compute the mean of each bootstrap sample.
- The lower bound is the 2.5th percentile and the upper bound is the 97.5th percentile of the bootstrap means.
Use numpy.random.seed(seed) before sampling.
Function signature:
def bootstrap_ci(X: list, b: int, seed: int) -> tuple:
# returns (lower, upper)
Input Format
Line 1: n b seed — number of data points, number of bootstrap samples, random seed
Lines 2..n+1: one float per line — the data values
Output Format
One line: lower upper — the 2.5th and 97.5th percentile of bootstrap means (10 significant figures)
Example
Input:
5 1000 42
1.0
2.0
3.0
4.0
5.0
Output:
1.8 4.2
Notes
- Use
numpy.random.choicewithreplace=Trueto draw bootstrap samples. - Use
numpy.percentilefor the 2.5 and 97.5 percentiles. - The confidence interval captures the variability of the sample mean estimator.
Bình luận