人类学中的线性模型
如果您只找到一具距今数千年的成年人的部分骨骼,如何估计这位个体的身高?本练习部分灵感来自法医人类学家 Mildred Trotter 的工作。她基于人体"长骨"(例如股骨)建立了一个回归模型,用于估计身高,如今仍被广泛使用。
在本练习中,您将使用多位在世个体的数据,并借助 Python 库 scikit-learn,构建一个线性模型,将股骨(大腿骨)长度与个体"身高"(整体身高)联系起来。随后,您将应用模型来预测一位古代祖先的身高。

本练习是课程的一部分
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]))