RMSE Step-by-step
In this exercise, you will quantify the over-all model "goodness-of-fit" of a pre-built model, by computing one of the most common quantitative measures of model quality, the RMSE, step-by-step.
Start with the pre-loaded data x_data
and y_data
, and use it with a predefined modeling function model_fit_and_predict()
.
This exercise is part of the course
Introduction to Linear Modeling in Python
Exercise instructions
- Compute
y_model
values frommodel_fit_and_predict(x_data, y_data)
. - Compute the
residuals
as the difference betweeny_model
andy_data
. - Use
np.sum()
andnp.square()
to computeRSS
, and divide bylen(residuals)
to getMSE
. - Take the
np.sqrt()
ofMSE
to getRMSE
, and print all results.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Build the model and compute the residuals "model - data"
y_model = model_fit_and_predict(x_data, y_data)
residuals = ____ - ____
# Compute the RSS, MSE, and RMSE and print the results
RSS = np.____(np.____(residuals))
MSE = ____/len(residuals)
RMSE = np.____(____)
print('RMSE = {:0.2f}, MSE = {:0.2f}, RSS = {:0.2f}'.format(RMSE, MSE, RSS))