Learn R Programming

rtemis (version 0.79)

bag: Bag an rtemis learner for regression or classification [C, R]

Description

Train a bagged ensemble using any learner

Usage

bag(x, y = NULL, x.test = NULL, y.test = NULL, weights = NULL,
  mod = "cart", k = 10, mod.params = list(), ipw = TRUE,
  ipw.type = 2, upsample = FALSE, upsample.seed = NULL,
  .resample = rtset.resample(resampler = "strat.boot", n.resamples = k),
  aggr.fn = mean, x.name = NULL, y.name = NULL, question = NULL,
  base.verbose = FALSE, verbose = TRUE, trace = 0,
  print.plot = TRUE, plot.fitted = NULL, plot.predicted = NULL,
  plot.theme = getOption("rt.fit.theme", "lightgrid"),
  print.base.plot = FALSE, n.cores = rtCores,
  parallel.type = ifelse(.Platform$OS.type == "unix", "fork", "psock"),
  outdir = NULL, ...)

Arguments

x

Numeric vector or matrix / data frame of features i.e. independent variables

y

Numeric vector of outcome, i.e. dependent variable

x.test

Numeric vector or matrix / data frame of testing set features Columns must correspond to columns in x

y.test

Numeric vector of testing set outcome

weights

Numeric vector: Weights for cases. For classification, weights takes precedence over ipw, therefore set weights = NULL if using ipw. Note: If weight are provided, ipw is not used. Leave NULL if setting ipw = TRUE. Default = NULL

mod

String: Algorithm to bag, for options, see modSelect

k

Integer: Number of base learners to train

mod.params

Named list of arguments for mod

ipw

Logical: If TRUE, apply inverse probability weighting (for Classification only). Note: If weights are provided, ipw is not used. Default = TRUE

ipw.type

Integer 0, 1, 2 1: class.weights as in 0, divided by max(class.weights) 2: class.weights as in 0, divided by min(class.weights) Default = 2

upsample

Logical: If TRUE, upsample cases to balance outcome classes (for Classification only) Caution: upsample will randomly sample with replacement if the length of the majority class is more than double the length of the class you are upsampling, thereby introducing randomness

upsample.seed

Integer: If provided, will be used to set the seed during upsampling. Default = NULL (random seed)

.resample

List: Resample settings to use. There is no need to edit this, unless you want to change the type of resampling. It will use stratified bootstrap by default. Use rtset.resample for convenience. Default = rtset.resample(resampler = "strat.boot", n.resamples = k)

aggr.fn

Function: used to average base learners' predictions. Default = mean. (Note: no quotes, as you are passing the function itself)

x.name

Character: Name for feature set

y.name

Character: Name for outcome

question

String: the question you are attempting to answer with this model, in plain language.

base.verbose

Logical: verbose argument passed to learner

verbose

Logical: If TRUE, print summary to screen.

trace

Integer: If > 0, print diagnostic info to console

print.plot

Logical: if TRUE, produce plot using mplot3 Takes precedence over plot.fitted and plot.predicted

plot.fitted

Logical: if TRUE, plot True (y) vs Fitted

plot.predicted

Logical: if TRUE, plot True (y.test) vs Predicted. Requires x.test and y.test

plot.theme

String: "zero", "dark", "box", "darkbox"

print.base.plot

Logical: Passed to print.plot argument of base learner, i.e. if TRUE, print error plot for each base learner

n.cores

Integer: Number of cores to use

parallel.type

String: "fork" or "psock". Type of parallelization. Default = "fork" for macOS and Linux, "psock" for Windows

outdir

Path to output directory. If defined, will save Predicted vs. True plot, if available, as well as full model output, if save.mod is TRUE

...

Additional parameters to be passed to learner