O'Reilly logo

R: Recipes for Analysis, Visualization and Machine Learning by Chiu Yu-Wei, Atmajitsinh Gohil, Shanthi Viswanathan, Viswa Viswanathan

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

Using random forest models for classification

The randomForest package can help you to easily apply the very powerful (but computationally intensive) random forest classification technique.

Getting ready

If you have not already installed the randomForest and caret packages, install them now. Download the data files for this chapter from the book's website and place the banknote-authentication.csv file in your R working directory. We will build a random forest model to predict class based on the other variables.

How to do it...

To use Random Forest models for classification, follow these steps:

  1. Load the randomForest and caret packages:
    > library(randomForest)
    > library(caret)
  2. Read the data and convert the response variable to a factor:
    > bn <- read.csv("banknote-authentication.csv") ...

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