This recipe looks at random forests—one of the most successful machine learning techniques.
If you have not already installed the
caret packages, install them now. Download the data files for this chapter from the book's website and place the
BostonHousing.csv file is in your R working directory. We will build a random forest model to predict
MEDV based on the other variables.
To build random forest models for regression, follow the steps below:
> library(randomForest) > library(caret)
> bn <- read.csv("BostonHousing.csv")
> set.seed(1000) > t.idx <- createDataPartition(bh$MEDV, p=0.7, list=FALSE) ...