Skip to contents

A wrapper for rpart::rpart() for use in nadir::super_learner().

Usage

lnr_rpart(data, formula, weights = NULL, ...)

Arguments

data

A dataframe to train a learner / learners on.

formula

A regression formula to use inside this learner.

weights

Observation weights; see ?lm

...

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 (a numeric vector of values, one for each row of newdata).

Details

A single regression tree is a classic member of super learner libraries: it is fast, handles interactions and nonlinearities automatically, and its predictions are piecewise-constant, complementing the smooth learners in the library. Complexity may be controlled through rpart.control arguments passed via ... (e.g., cp, minsplit, maxdepth).

See also

learners

Examples

lnr_rpart(mtcars, mpg ~ hp + disp + wt)(mtcars)
#>  [1] 20.75455 20.75455 29.02857 20.75455 15.10000 20.75455 15.10000 20.75455
#>  [9] 20.75455 20.75455 20.75455 15.10000 15.10000 15.10000 15.10000 15.10000
#> [17] 15.10000 29.02857 29.02857 29.02857 20.75455 15.10000 15.10000 15.10000
#> [25] 15.10000 29.02857 29.02857 29.02857 15.10000 20.75455 15.10000 20.75455
lnr_rpart(mtcars, mpg ~ ., cp = 0.05)(mtcars)
#>  [1] 18.26429 18.26429 26.66364 18.26429 18.26429 18.26429 13.41429 26.66364
#>  [9] 26.66364 18.26429 18.26429 18.26429 18.26429 18.26429 13.41429 13.41429
#> [17] 13.41429 26.66364 26.66364 26.66364 26.66364 18.26429 18.26429 13.41429
#> [25] 18.26429 26.66364 26.66364 26.66364 13.41429 18.26429 13.41429 26.66364