Evaluate the regression tree
In this exercise, you will evaluate the test set performance of dt
using the Root Mean Squared Error (RMSE) metric. The RMSE of a model measures, on average, how much the model's predictions differ from the actual labels. The RMSE of a model can be obtained by computing the square root of the model's Mean Squared Error (MSE).
The features matrix X_test
, the array y_test
, as well as the decision tree regressor dt
that you trained in the previous exercise are available in your workspace.
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
- Import the function
mean_squared_error
asMSE
fromsklearn.metrics
. - Predict the test set labels and assign the output to
y_pred
. - Compute the test set MSE by calling
MSE
and assign the result tomse_dt
. - Compute the test set RMSE and assign it to
rmse_dt
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import mean_squared_error from sklearn.metrics as MSE
from ____.____ import ____ as ____
# Compute y_pred
____ = ____.____(____)
# Compute mse_dt
____ = ____(____, ____)
# Compute rmse_dt
____ = ____
# Print rmse_dt
print("Test set RMSE of dt: {:.2f}".format(rmse_dt))