Get startedGet started for free

Regression performance

Now you have fit a model, reg, using all features from sales_df, and made predictions of sales values, you can evaluate performance using some common regression metrics.

The variables X_train, X_test, y_train, y_test, and y_pred, along with the fitted model, reg, all from the last exercise, have been preloaded for you.

Your task is to find out how well the features can explain the variance in the target values, along with assessing the model's ability to make predictions on unseen data.

This exercise is part of the course

Supervised Learning with scikit-learn

View Course

Exercise instructions

  • Import mean_squared_error.
  • Calculate the model's R-squared score by passing the test feature values and the test target values to an appropriate method.
  • Calculate the model's root mean squared error using y_test and y_pred.
  • Print r_squared and rmse.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import mean_squared_error
from ____.____ import ____

# Compute R-squared
r_squared = reg.____(____, ____)

# Compute RMSE
rmse = ____(____, ____, squared=____)

# Print the metrics
print("R^2: {}".format(____))
print("RMSE: {}".format(____))
Edit and Run Code