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 necessary packages and step 2 reads the data and converts the response variable to a factor.

Step 3 sets aside some of the data for later use. Strictly speaking, we do not have to partition the data for random forests because, while building each tree, the method sets aside some of the cases for cross-validation. However, we set aside some of the cases just to illustrate the process of using the model for prediction. (We set the random seed to enable you to match your results with those that we display.)

Step 4 uses the randomForest function to build the model. As the predictor variables are in the first four variables of the data frame and we want to use only the selected subset for model building, we specify ...

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