Database Reference
In-Depth Information
library ( ' ' randomForest ' ' )
#splitthedataintototrainandtest
trainIndex
<
sample ( nrow (iris), 2 / 3
nrow (iris))
<
trainData
iris [ trainIndex ,]
<
testData
iris[
trainIndex ,]
#buildtheforest
irisRandomForest
<
randomForest( Species ˜ .,
data =trainData)
# predict on test data
testPrediction
<
predict (irisRandomForest ,
newdata = testData)
# show the confusion matrix
table (testPrediction , testData $ Species )
The function randomForest() has several arguments that control the
execution of the algorithm, such as: ntree (Number of trees to grow),
mtry (Number of attributes randomly sampled as candidates at each split),
replace - (whether sampling of cases can be done with or without a
replacement), sampsize (the sizes of the samples to draw) and nodesize
(Minimum size of terminal nodes). Finally, the random Forest package
provides additional useful functions such as the function getTree() for
extracting a certain single tree from a forest and the function grow() for
adding additional trees to an existing forest.
Search WWH ::




Custom Search