How to do it...

Perform the following steps to measure the performance of the regression model:

  1. Load the Quartet dataset from the car package:
        > library(car)
        > data(Quartet)
  1. Plot the attribute, y3, against x using the lm function:
        > plot(Quartet$x, Quartet$y3)
        > lmfit = lm(Quartet$y3~Quartet$x)
        > abline(lmfit, col="red")  
The linear regression plot
  1. You can retrieve predicted values by using the predict function:
        > predicted= predict(lmfit, newdata=Quartet[c("x")])  
  1. Now, you can calculate the root mean square error:
        > actual = Quartet$y3
        > rmse = (mean((predicted - actual)^2))^0.5
        > rmse
        Output
        [1] 1.118286  
  1. You can calculate the ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.