인류학에서의 선형 모델
수천 년 전 살았던 성인 인간의 골격 일부를 발견했다면, 그 사람이 얼마나 키가 컸는지 어떻게 추정할 수 있을까요? 이 연습 문제는 법의인류학자 Mildred Trotter의 연구에서 영감을 받았습니다. 그는 오늘날 널리 쓰이는, 인간의 "long bone"(대퇴골)을 이용해 신장(키)을 추정하는 회귀 모델을 구축했어요.
이 연습에서는 많은 현대인의 데이터를 사용하고, Python 라이브러리 scikit-learn을 이용해 대퇴골(넓적다리뼈) 길이와 사람의 "stature"(전체 키) 사이의 선형 모델을 만들어 볼 거예요. 그런 다음, 이 모델을 사용해 고대 조상의 키를 예측해 보겠습니다.

이 연습은 강의의 일부입니다
Python으로 배우는 선형 모델 입문
연습 안내
sklearn.linear_model에서LinearRegression을 import하고,fit_intercept=False로 모델을 초기화하세요.- 미리 로드된 데이터 배열
legs와heights를 "1-by-N"에서 "N-by-1" 배열로 재구조화하세요. - 재구조화한
legs와heights를model.fit()에 전달하세요. model.predict()를 사용해 새로 발견한 화석fossil_leg = 50.7에 대한 예측값fossil_height를 구하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# import the sklearn class LinearRegression and initialize the model
from sklearn.____ import ____
model = LinearRegression(fit_intercept=False)
# Prepare the measured data arrays and fit the model to them
legs = legs.reshape(len(____),1)
heights = heights.reshape(len(____),1)
model.fit(____, heights)
# Use the fitted model to make a prediction for the found femur
fossil_leg = np.array(50.7).reshape(1, -1)
fossil_height = model.predict(____)
print("Predicted fossil height = {:0.2f} cm".format(fossil_height[0,0]))