Training a random forest model using the randomForest package is simple. Take a look at the following code:
rfModel <- randomForest(x=trainX, y=factor(trainY), ntree=200, maxnodes=24)
Using the randomForest function in the randomForest package, you can easily train a random forest model. You just need to supply the train set to the function. For illustration purposes, we are instructing the model to build 200 trees, where each tree can only grow up to 24 terminal nodes.
When you run this code, your model object will look as follows:
Once a random forest model is trained or fitted, the model object contains ...