Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Machine Learning with Tree-Based Models in Python

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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))
Code bewerken en uitvoeren