Kom igångKom igång gratis

Building a random forest model

In spite of the fact that a forest can contain hundreds of trees, growing a decision tree forest is perhaps even easier than creating a single highly-tuned tree.

Using the randomForest package, build a random forest and see how it compares to the single trees you built previously.

The loans_train and loans_test datasets are pre-loaded for you.

Keep in mind that due to the random nature of the forest, the results may vary slightly each time you create the forest.

Den här övningen är en del av kursen

Supervised Learning in R: Classification

Visa kurs

Övningsinstruktioner

  • Load the randomForest package.
  • Build a random forest model using all of the loan application variables. The randomForest function also uses the formula interface.
  • Compute the accuracy of the random forest model to compare to the original tree's accuracy of 57.6% using predict() and mean().

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

# Load the randomForest package
___

# Build a random forest model
loan_model <- ___(___, data = ___)

# Compute the accuracy of the random forest
loans_test$pred <- ___
mean(___)
Redigera och kör kod