IniziaInizia gratis

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)

Questo esercizio fa parte del corso

Machine Learning with Tree-Based Models in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Import mean_squared_error as MSE from sklearn.metrics.

  • Extract the best estimator from grid_rf and assign it to best_model.

  • Predict best_model's test set labels and assign the result to y_pred.

  • Compute best_model's test set RMSE.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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)) 
Modifica ed esegui il codice