Linear regression vs regression tree

In this exercise, you'll compare the test set RMSE of dt to that achieved by a linear regression model. We have already instantiated a linear regression model lr and trained it on the same dataset as dt.

The features matrix X_test, the array of labels y_test, the trained linear regression model lr, mean_squared_error function which was imported under the alias MSE and rmse_dt from the previous exercise are available in your workspace.

This exercise is part of the course

Machine Learning with Tree-Based Models in Python

View Course

Exercise instructions

  • Predict test set labels using the linear regression model (lr) and assign the result to y_pred_lr.

  • Compute the test set MSE and assign the result to mse_lr.

  • Compute the test set RMSE and assign the result to rmse_lr.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Predict test set labels 
____ = ____.____(____)

# Compute mse_lr
____ = ____(____, ____)

# Compute rmse_lr
____ = ____

# Print rmse_lr
print('Linear Regression test set RMSE: {:.2f}'.format(rmse_lr))

# Print rmse_dt
print('Regression Tree test set RMSE: {:.2f}'.format(rmse_dt))