선형 회귀
1975년과 2012년 데이터 각각에 대해 선형 회귀를 수행하세요. 그런 다음 회귀 모수에 대해 페어 부트스트랩 추정을 수행하세요. 회귀선의 기울기와 절편에 대한 95% 신뢰 구간을 보고하세요.
[챕터 2에서 작성했던](https://campus.datacamp.com/courses/statistical-thinking-in-python-part-2/bootstrap-confidence-intervals?ex=12) draw_bs_pairs_linreg() 함수를 사용하게 됩니다.
참고로, 이 함수의 호출 시그니처는 draw_bs_pairs_linreg(x, y, size=1)이며, bs_slope_reps와 bs_intercept_reps를 반환합니다. 부리 길이 데이터는 bl_1975와 bl_2012에, 부리 깊이 데이터는 bd_1975와 bd_2012에 저장되어 있어요.
이 연습은 강의의 일부입니다
Python으로 하는 통계적 사고 (2부)
연습 안내
- 1975년과 2012년 두 데이터셋 모두에 대해 기울기와 절편을 계산하세요.
draw_bs_pairs_linreg()함수를 사용해 선형 회귀에 대한 페어 부트스트랩 표본 1000개를 얻으세요.- 기울기와 절편 각각에 대해 95% 신뢰 구간을 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Compute the linear regressions
slope_1975, intercept_1975 = ____
slope_2012, intercept_2012 = ____
# Perform pairs bootstrap for the linear regressions
bs_slope_reps_1975, bs_intercept_reps_1975 = \
____
bs_slope_reps_2012, bs_intercept_reps_2012 = \
____
# Compute confidence intervals of slopes
slope_conf_int_1975 = ____
slope_conf_int_2012 = ____
intercept_conf_int_1975 = ____
intercept_conf_int_2012 = ____
# Print the results
print('1975: slope =', slope_1975,
'conf int =', slope_conf_int_1975)
print('1975: intercept =', intercept_1975,
'conf int =', intercept_conf_int_1975)
print('2012: slope =', slope_2012,
'conf int =', slope_conf_int_2012)
print('2012: intercept =', intercept_2012,
'conf int =', intercept_conf_int_2012)