Discretize Numeric VariablesSource:
step_discretize creates a specification of a recipe
step that will convert numeric data into a factor with
bins having approximately the same number of data points (based
on a training set).
A recipe object. The step will be added to the sequence of operations for this recipe.
One or more selector functions to choose variables for this step. See
selections()for more details.
Not used by this step since no new variables are created.
A logical to indicate if the quantities for preprocessing have been estimated.
An integer defining how many cuts to make of the data.
An integer defining a sample size line of dignity for the binning. If (the number of unique values)
/(cuts+1)is less than
min_unique, no discretization takes place.
A list of options to
discretize(). A default is set for the argument
x. Note that using the options
labelswhen more than one variable is being transformed might be problematic as all variables inherit those values.
A logical. Should the step be skipped when the recipe is baked by
bake()? While all operations are baked when
prep()is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using
skip = TRUEas it may affect the computations for subsequent operations.
A character string that is unique to this step to identify it.
An updated version of
recipe with the new step added to the
sequence of any existing operations.
tidy() this step, a tibble with columns
terms (the selectors or variables selected) and
(the breaks) is returned.
Other discretization steps:
data(biomass, package = "modeldata") biomass_tr <- biomass[biomass$dataset == "Training", ] biomass_te <- biomass[biomass$dataset == "Testing", ] rec <- recipe( HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur, data = biomass_tr ) %>% step_discretize(carbon, hydrogen) rec <- prep(rec, biomass_tr) #> Warning: Note that the options `prefix` and `labels`will be applied to all variables binned_te <- bake(rec, biomass_te) table(binned_te$carbon) #> #> bin1 bin2 bin3 bin4 #> 22 17 25 16 tidy(rec, 1) #> # A tibble: 10 × 3 #> terms value id #> <chr> <dbl> <chr> #> 1 carbon -Inf discretize_hhrhR #> 2 carbon 44.7 discretize_hhrhR #> 3 carbon 47.1 discretize_hhrhR #> 4 carbon 49.7 discretize_hhrhR #> 5 carbon Inf discretize_hhrhR #> 6 hydrogen -Inf discretize_hhrhR #> 7 hydrogen 5.20 discretize_hhrhR #> 8 hydrogen 5.78 discretize_hhrhR #> 9 hydrogen 6.05 discretize_hhrhR #> 10 hydrogen Inf discretize_hhrhR