开始使用免费开始使用

用于预测收入的 Boosting

初始模型的 RMSE 约为 7.34。让我们看看能否通过一次 boosting 迭代来改进这一结果。

您将再训练一个线性回归模型,但这次的目标值是基模型的误差,计算方式如下:

y_train_error = pred_train - y_train
y_test_error = pred_test - y_test

对于这个模型,您将改用 'popularity' 特征,希望它比仅使用 'budget' 特征能提供更有信息量的模式。对应的数据为 X_train_popX_test_pop。与上一个练习相同,输入特征已为您标准化。

本练习是课程的一部分

Python 中的集成方法

查看课程

练习说明

  • 使用 X_train_popy_train_error,对先前的误差拟合一个线性回归模型。
  • 在测试集 X_test_pop 上计算预测误差。
  • 按照上一个练习的方法,使用 y_test_errorpred_error 计算 RMSE。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Fit a linear regression model to the previous errors
reg_error = LinearRegression()
____

# Calculate the predicted errors on the test set
pred_error = ____

# Evaluate the updated performance
rmse_error = ____
print('RMSE: {:.3f}'.format(rmse_error))
编辑并运行代码