Random forest is another useful ensemble learning method that grows multiple decision trees during the training process. Each decision tree will output its own prediction results corresponding to the input. The forest will use the voting mechanism to select the most voted class as the prediction result. In this recipe, we will illustrate how to classify data using the randomForest
package.
In this recipe, we will continue to use the telecom churn
dataset as the input data source to perform classifications with the random forest method.
Perform the following steps to classify data with random forest:
- First, you have to install and load the
randomForest
package:
> install.packages("randomForest")> library(randomForest)
- You can then fit the random forest classifier with a training set:
> churn.rf = randomForest(churn ~ ., data = trainset, importance = T) > churn.rf Output Call: ...