combine.wsrf: Combine Ensembles of Trees

View source: R/combine.wsrf.R

combine.wsrfR Documentation

Combine Ensembles of Trees

Description

Combine two more more ensembles of trees into one.

Usage

combine(...)

Arguments

...

two or more objects of class randomForest, to be combined into one.

Value

An object of class wsrf.

See Also

subset

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))


wsrf documentation built on Jan. 6, 2023, 5:06 p.m.