Description Usage Arguments Value Examples
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
.
1 |
type |
the type of the prediction problem.
One of |
A function to be used in the train
function of the caret
package.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.