O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

When using any regression technique, you will be able to generate predictions. This recipe shows you how to calculate the RMS error, given the predicted and actual numerical values of the outcome variable:

  1. Compute the RMS error as follows:
> dat <- read.csv("rmse-example.csv") 
> rmse <- sqrt(mean((dat$price-dat$pred)^2)) 
> rmse 
 
[1] 2.934995 
  1. Plot the results, and show the 45-degree line:
> plot(dat$price, dat$pred, xlab = "Actual",  ylab = "Predicted") 
> abline(0, 1) 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required