Skip to contents

A wrapper for rpart::rpart() with method = 'class' for use in nadir::super_learner() with binary outcomes.

Usage

lnr_rpart_binary(data, formula, weights = NULL, bound = 0.0025, ...)

Arguments

data

A dataframe to train a learner / learners on.

formula

A regression formula to use inside this learner.

weights

Observation weights; see ?lm

bound

Predicted probabilities are truncated into [bound, 1 - bound] to avoid infinite negative log loss from pure terminal nodes.

...

Any extra arguments that should be passed to the internal model for model fitting purposes.

Value

A prediction function that accepts newdata, which returns predictions for the probability of the outcome being 1/TRUE (a numeric vector of values, one for each row of newdata).

Details

Because classification trees can produce pure terminal nodes, raw predicted probabilities of exactly 0 or 1 are possible, which yield infinite negative log loss on held-out data where such predictions are wrong. To keep lnr_rpart_binary compatible with determine_weights_for_binary_outcomes, predicted probabilities are bounded into [bound, 1 - bound]. Set bound = 0 to disable this behavior.

See also

binary_learners

Examples

lnr_rpart_binary(mtcars, am ~ hp + mpg)(mtcars)
#>  [1] 0.7333333 0.7333333 0.7333333 0.7333333 0.1176471 0.1176471 0.1176471
#>  [8] 0.7333333 0.7333333 0.1176471 0.1176471 0.1176471 0.1176471 0.1176471
#> [15] 0.1176471 0.1176471 0.1176471 0.7333333 0.7333333 0.7333333 0.7333333
#> [22] 0.1176471 0.1176471 0.1176471 0.1176471 0.7333333 0.7333333 0.7333333
#> [29] 0.1176471 0.7333333 0.1176471 0.7333333