부트스트랩 시각화
이번 레슨에서 이어서, 부트스트랩 리샘플링으로 추정한 속도의 부트스트랩 분포를 시각화해 보겠습니다. 각 샘플에 대해 기울기의 최소제곱 적합을 계산하여, 기울기 추정의 변동성(불확실성)을 확인했었죠.
시작할 수 있도록, 속도 표본 분포를 생성하는 계산을 수행하는 함수 compute_resample_speeds(distances, times)를 미리 로드해 두었습니다.

이 연습은 강의의 일부입니다
Python으로 배우는 선형 모델 입문
연습 안내
- 미리 정의된
compute_resample_speeds(distances, times)를 사용해resample_speeds를 계산하세요. np.mean()으로resample_speeds에서speed_estimate를 계산하세요.np.percentile()에[5, 95]를 사용해resample_speeds의percentiles를 계산하세요. 이는 신뢰 구간 경계를 정의합니다.axis.hist()를 사용해resample_speeds를 그리되,hist_bin_edges로 구간 경계를 지정하세요.axis.axvline을 사용해 차트에 신뢰 구간 경계를 표시하도록percentiles의 올바른 두 인덱스를 지정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create the bootstrap distribution of speeds
resample_speeds = compute_resample_speeds(____, ____)
speed_estimate = np.mean(____)
percentiles = np.percentile(____, [5, 95])
# Plot the histogram with the estimate and confidence interval
fig, axis = plt.subplots()
hist_bin_edges = np.linspace(0.0, 4.0, 21)
axis.hist(____, ____, color='green', alpha=0.35, rwidth=0.8)
axis.axvline(speed_estimate, label='Estimate', color='black')
axis.axvline(percentiles[____], label=' 5th', color='blue')
axis.axvline(percentiles[____], label='95th', color='blue')
axis.legend()
plt.show()