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 it works...

Step 1 loads the caret package, step 2 reads the data, and step 3 converts the categorical variable cylinders (which have numeric values that R treats as numbers by default) into factors.

Step 4 creates the partitions (refer to the Creating random data partitions recipe in Chapter 2, What's In There? - Exploratory Data Analysis for more details). We set the random seed to enable you to match your results with what we have displayed.

Step 5 prints the variable names in the file so that we can use the appropriate variables in the linear regression model.

Step 6 uses the lm function that builds the linear regression model. We specified data = auto[t.idx, -c(1,8,9)] because we want the model to use only the training data and because ...

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