Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tuneRF

Tune randomForest for the optimal mtry parameter


Description

Starting with the default value of mtry, search for the optimal value (with respect to Out-of-Bag error estimate) of mtry for randomForest.

Usage

tuneRF(x, y, mtryStart, ntreeTry=50, stepFactor=2, improve=0.05,
       trace=TRUE, plot=TRUE, doBest=FALSE, ...)

Arguments

x

matrix or data frame of predictor variables

y

response vector (factor for classification, numeric for regression)

mtryStart

starting value of mtry; default is the same as in randomForest

ntreeTry

number of trees used at the tuning step

stepFactor

at each iteration, mtry is inflated (or deflated) by this value

improve

the (relative) improvement in OOB error must be by this much for the search to continue

trace

whether to print the progress of the search

plot

whether to plot the OOB error as function of mtry

doBest

whether to run a forest using the optimal mtry found

...

options to be given to randomForest

Value

If doBest=FALSE (default), it returns a matrix whose first column contains the mtry values searched, and the second column the corresponding OOB error.

If doBest=TRUE, it returns the randomForest object produced with the optimal mtry.

See Also

Examples

data(fgl, package="MASS")
fgl.res <- tuneRF(fgl[,-10], fgl[,10], stepFactor=1.5)

randomForest

Breiman and Cutler's Random Forests for Classification and Regression

v4.6-14
GPL (>= 2)
Authors
Fortran original by Leo Breiman and Adele Cutler, R port by Andy Liaw and Matthew Wiener.
Initial release
2018-03-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.