A recipe records which transformations to apply to the predictors;
morie_ml_prep() estimates their parameters from training data and
morie_ml_bake() applies (or reverses) them. This is the dedicated
pre-processing-specification stage: it is defined and parametrised
separately from model fitting, records the values of all
transformations, and can be switched off.
Usage
morie_ml_recipe(
outcome,
predictors = NULL,
impute = c("mean", "median", "none"),
center = TRUE,
scale = TRUE,
center_target = NULL
)Arguments
- outcome
Name of the response column.
- predictors
Character vector of predictor columns (default: all other numeric columns).
- impute
One of "none", "mean", "median" (ML1.7a; default "mean").
- center
Logical; center predictors (ML2.2). Default TRUE.
- scale
Logical; scale predictors to unit SD. Default TRUE.
- center_target
Optional named numeric of explicit target means (ML2.2); overrides the data mean where supplied.
Examples
rec <- morie_ml_recipe("mpg", c("hp", "wt"))
rec <- morie_ml_prep(rec, mtcars)
head(morie_ml_bake(rec, mtcars))
#> mpg cyl disp hp drat wt qsec vs am gear
#> Mazda RX4 21.0 6 160 -0.5350928 3.90 -0.610399567 16.46 0 1 4
#> Mazda RX4 Wag 21.0 6 160 -0.5350928 3.90 -0.349785269 17.02 0 1 4
#> Datsun 710 22.8 4 108 -0.7830405 3.85 -0.917004624 18.61 1 1 4
#> Hornet 4 Drive 21.4 6 258 -0.5350928 3.08 -0.002299538 19.44 1 0 3
#> Hornet Sportabout 18.7 8 360 0.4129422 3.15 0.227654255 17.02 0 0 3
#> Valiant 18.1 6 225 -0.6080186 2.76 0.248094592 20.22 1 0 3
#> carb
#> Mazda RX4 4
#> Mazda RX4 Wag 4
#> Datsun 710 1
#> Hornet 4 Drive 1
#> Hornet Sportabout 2
#> Valiant 1
