CommencerCommencer gratuitement

Calculate RMSE

In this exercise, you will calculate the RMSE of your unemployment model. In the previous coding exercises, you added two columns to the unemployment dataset:

  • the model's predictions (predictions column)
  • the residuals between the predictions and the outcome (residuals column)

You can calculate the RMSE from a vector of residuals, \(res\), as:

$$ RMSE = \sqrt{\operatorname{mean}(res^2)} $$

You want RMSE to be small. How small is "small"? One heuristic is to compare the RMSE to the standard deviation of the outcome. With a good model, the RMSE should be smaller.

The unemployment data frame has been loaded for you.

Cet exercice fait partie du cours

Supervised Learning in R: Regression

Afficher le cours

Instructions

  • Review the unemployment data from the previous exercise.
  • For convenience, assign the residuals column from unemployment to the variable res.
  • Calculate RMSE: square res, take its mean, and then square root it. Assign this to the variable rmse and print it.
    • Tip: you can do this in one step by wrapping the assignment in parentheses: (rmse <- ___)
  • Calculate the standard deviation of female_unemployment and assign it to the variable sd_unemployment. Print it. How does the rmse of the model compare to the standard deviation of the data?

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Print a summary of unemployment
summary(unemployment)

# For convenience put the residuals in the variable res
res <- ___

# Calculate RMSE, assign it to the variable rmse and print it
(rmse <- ___)

# Calculate the standard deviation of female_unemployment and print it
(sd_unemployment <- ___)
Modifier et exécuter le code