R Data Analysis Cookbook, Second Edition - Second Edition
by Kuntal Ganguly, Davor Lozić, Mzabalazo Z. Ngwenya, Andrew Bauman, Shanthi Viswanathan, Viswa Viswanathan
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access