combine.wsrf {wsrf} | R Documentation |
Combine Ensembles of Trees
Description
Combine two more more ensembles of trees into one.
Usage
combine(...)
Arguments
... |
two or more objects of class |
Value
An object of class wsrf
.
See Also
Examples
library("wsrf")
# Prepare parameters.
ds <- iris
target <- "Species"
vars <- names(ds)
if (sum(is.na(ds[vars]))) ds[vars] <- randomForest::na.roughfix(ds[vars])
ds[target] <- as.factor(ds[[target]])
form <- as.formula(paste(target, "~ ."))
set.seed(42)
train.1 <- sample(nrow(ds), 0.7*nrow(ds))
test.1 <- setdiff(seq_len(nrow(ds)), train.1)
set.seed(49)
train.2 <- sample(nrow(ds), 0.7*nrow(ds))
test.2 <- setdiff(seq_len(nrow(ds)), train.2)
# Build model. We disable parallelism here, since CRAN Repository
# Policy (https://cran.r-project.org/web/packages/policies.html)
# limits the usage of multiple cores to save the limited resource of
# the check farm.
model.wsrf.1 <- wsrf(form, data=ds[train.1, vars], parallel=FALSE)
model.wsrf.2 <- wsrf(form, data=ds[train.2, vars], parallel=FALSE)
# Merge two models.
model.wsrf.big <- combine.wsrf(model.wsrf.1, model.wsrf.2)
print(model.wsrf.big)
cl <- predict(model.wsrf.big, newdata=ds[test.1, vars], type="response")$response
actual <- ds[test.1, target]
(accuracy.wsrf <- mean(cl==actual))
[Package wsrf version 1.7.30 Index]