人類學中的線性模型
如果你找到了一段數千年前成人的人類骨骼,要怎麼估計這個人的身高?本練習的靈感部分來自法醫人類學家 Mildred Trotter 的工作。她建立了以人類「長骨」——股骨——來推算身高的迴歸模型,至今仍被廣泛使用。
在這個練習中,你會使用許多現代人的資料,並透過 Python 函式庫 scikit-learn,建立一個將股骨(大腿骨)長度與個人「身高」(stature)連結的線性模型。接著,你會套用這個模型來預測你那位遠古祖先的身高。

本練習屬於課程
Python 線性建模入門
練習說明
- 從
sklearn.linear_model匯入LinearRegression,並以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]))