创建 LASSO 回归器
您将使用数值型的 ANSUR 身体测量数据集,通过预先导入的 Lasso() 回归器来预测个人的身体质量指数(BMI)。BMI 是由身高和体重推导出的指标,但这两个特征已从数据集中移除,以增加模型的挑战。
首先请使用已为您实例化为 scaler 的 StandardScaler() 对数据进行标准化,确保所有系数都受到可比较的正则化力度的约束,从而被压缩。
所有必要的函数与类,以及输入数据集 X 和 y 均已预加载。
本练习是课程的一部分
Python 中的降维
练习说明
- 将测试集比例设为 30%,得到 70-30% 的训练/测试划分。
- 在训练特征上拟合 scaler,并一次性完成拟合与变换。
- 创建 Lasso 模型。
- 将其拟合到缩放后的训练数据上。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Set the test size to 30% to get a 70-30% train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=____, random_state=0)
# Fit the scaler on the training features and transform these in one go
X_train_std = scaler.____
# Create the Lasso model
la = ____()
# Fit it to the standardized training data
la.____