R(28), Random Forest

Published: by Creative Commons Licence

The package named "randomForest" is needed.

install.packages("randomForest")

There is a function named randomForest() in package randomForest that can be used to create and analysis the random forest.

randomForest(formula, data)
  • formula: a data frame or a matrix of predictors, or a formula describing the model to be fitted (for the print method, an randomForest object).
  • data: an optional data frame containing the variables in the model. By default the variables are taken from the environment which randomForest is called from.
# Load the party package. It will automatically load other required packages.
library(party)
library(randomForest)

# Create the forest.
output.forest <- randomForest(nativeSpeaker ~ age + shoeSize + score, data = readingSkills)

# View the forest results.
print(output.forest) 

# Importance of each predictor.
print(importance(fit,type = 2))