선형 회귀 결과 표시하기
이제 산점도 위에 선형 회귀 결과를 표시해 보겠습니다. 산점도를 그리는 코드는 이전 연습 문제에서 미리 작성되어 있어요. 이를 위해 bs_slope_reps_1975, bs_intercept_reps_1975, bs_slope_reps_2012, bs_intercept_reps_2012에 저장된 처음 100개의 부트스트랩 샘플을 사용해 선을 그리세요. plt.plot()에 alpha=0.2, linewidth=0.5 키워드 인자를 지정하세요.
이 연습은 강의의 일부입니다
Python으로 하는 통계적 사고 (2부)
연습 안내
np.array()를 사용해 부트스트랩 선을 위한 x값을 생성하세요. 값은 10 mm와 17 mm로 구성되어야 해요.- 1975년과 2012년 데이터셋에 대해 각각 100개의 부트스트랩 선을 그리는
for루프를 작성하세요. 1975년 데이터셋의 선은'blue', 2012년 데이터셋의 선은'red'여야 해요. - Submit Answer를 눌러 플롯을 확인하세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Make scatter plot of 1975 data
_ = plt.plot(bl_1975, bd_1975, marker='.',
linestyle='none', color='blue', alpha=0.5)
# Make scatter plot of 2012 data
_ = plt.plot(bl_2012, bd_2012, marker='.',
linestyle='none', color='red', alpha=0.5)
# Label axes and make legend
_ = plt.xlabel('beak length (mm)')
_ = plt.ylabel('beak depth (mm)')
_ = plt.legend(('1975', '2012'), loc='upper left')
# Generate x-values for bootstrap lines: x
x = np.array([____, ____])
# Plot the bootstrap lines
for i in range(100):
plt.plot(____, ____,
linewidth=0.5, alpha=0.2, color=____)
plt.plot(____, ____,
linewidth=0.5, alpha=0.2, color=____)
# Draw the plot again
plt.show()