Evaluate the optimal forest
In this last exercise of the course, you'll evaluate the test set RMSE of grid_rf's optimal model.
The dataset is already loaded and processed for you and is split into 80% train and 20% test. In your environment are available X_test, y_test and the function mean_squared_error from sklearn.metrics under the alias MSE. In addition, we have also loaded the trained GridSearchCV object grid_rf that you instantiated in the previous exercise. Note that grid_rf was trained as follows:
grid_rf.fit(X_train, y_train)
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
Import
mean_squared_errorasMSEfromsklearn.metrics.Extract the best estimator from
grid_rfand assign it tobest_model.Predict
best_model's test set labels and assign the result toy_pred.Compute
best_model's test set RMSE.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import mean_squared_error from sklearn.metrics as MSE
____
# Extract the best estimator
best_model = ____
# Predict test set labels
y_pred = ____
# Compute rmse_test
rmse_test = ____
# Print rmse_test
print('Test RMSE of best model: {:.3f}'.format(rmse_test))