Predicting on the test set
In the last exercise, linear regression and ridge appeared to produce similar results. It would be appropriate to select either of those models; however, you can check predictive performance on the test set to see if either one can outperform the other.
You will use root mean squared error (RMSE) as the metric. The dictionary models
, containing the names and instances of the two models, has been preloaded for you along with the training and target arrays X_train_scaled
, X_test_scaled
, y_train
, and y_test
.
This exercise is part of the course
Supervised Learning with scikit-learn
Exercise instructions
- Import
mean_squared_error
. - Fit the model to the scaled training features and the training labels.
- Make predictions using the scaled test features.
- Calculate RMSE by passing the test set labels and the predicted labels.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import mean_squared_error
from ____.____ import ____
for name, model in models.items():
# Fit the model to the training data
____
# Make predictions on the test set
y_pred = ____
# Calculate the test_rmse
test_rmse = ____(____, ____, squared=____)
print("{} Test Set RMSE: {}".format(name, test_rmse))