step_discretize {recipes} | R Documentation |
Discretize Numeric Variables
Description
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).
Usage
step_discretize(
recipe,
...,
role = NA,
trained = FALSE,
num_breaks = 4,
min_unique = 10,
objects = NULL,
options = list(prefix = "bin"),
skip = FALSE,
id = rand_id("discretize")
)
Arguments
recipe |
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 |
role |
Not used by this step since no new variables are created. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
num_breaks |
An integer defining how many cuts to make of the data. |
min_unique |
An integer defining a sample size line of
dignity for the binning. If (the number of unique
values) |
objects |
The |
options |
A list of options to |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A character string that is unique to this step to identify it. |
Value
An updated version of recipe
with the new step added to the
sequence of any existing operations.
Tidying
When you tidy()
this step, a tibble is returned with
columns terms
, value
, and id
:
- terms
character, the selectors or variables selected
- value
numeric, the breaks
- id
character, id of this step
Tuning Parameters
This step has 2 tuning parameters:
-
min_unique
: Unique Value Threshold (type: integer, default: 10) -
num_breaks
: Number of Cut Points (type: integer, default: 4)
Case weights
The underlying operation does not allow for case weights.
See Also
Other discretization steps:
step_cut()
Examples
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)
binned_te <- bake(rec, biomass_te)
table(binned_te$carbon)
tidy(rec, 1)