rfcv2: Customized function for training random forest

Description Usage Arguments Value Examples

View source: R/rfcv2.R

Description

rfcv2 creates a random forest model which has both mtry and ntree as tuning parameters for cross-validations. This function is an extension to random forest models that are currently supported by the train function of the caret package as all of those models just use mtry.

Usage

1

Arguments

type

the type of the prediction problem. One of Regression and Classification.

Value

A function to be used in the train function of the caret package.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(caret)
library(randomForest)
library(mlbench)

#######################################
## Classification Example
data(iris)

set.seed(0)
rf_class_fit = train(Species ~ .,
                     data=iris,
                     method=rfcv2("Classification"),
                     tuneGrid=expand.grid(
                       .mtry=seq(1,ncol(iris)-1, 1),
                       .ntree=seq(100,500,100)),
                     trControl=trainControl(method="cv"))
print(rf_class_fit)

#######################################
## Regression Example
data(BostonHousing)

set.seed(0)
rf_reg_fit = train(medv ~ .,
                   data = BostonHousing,
                   method=rfcv2("Regression"),
                   tuneGrid=expand.grid(
                     .mtry=seq(1,sqrt(ncol(BostonHousing)-1), 1),
                     .ntree=seq(100,500,100)),
                   trControl=trainControl(method="cv"))
print(rf_reg_fit)

jitonglou/MultiMlearn documentation built on Dec. 21, 2021, 12:08 a.m.