Skip to content

Keep original labels in step_discretize #674

@renanxcortes

Description

@renanxcortes

Hi there!

I'd like to ask for a feature that would keep the original labels generated by the internal cut function in discretize, instead of "bin1", bin2", etc. Perhaps adding an argument keep_cut_labels = TRUE, for example.

Minimal Reproducible Example:

Current Behaviour:

library(modeldata)
data(biomass)

biomass_tr <- biomass[biomass$dataset == "Training",]
biomass_te <- biomass[biomass$dataset == "Testing",]

rec <- recipe(HHV ~ carbon,
              data = biomass_tr) %>% 
  step_discretize(carbon)

rec <- prep(rec, biomass_tr)
binned_te <- bake(rec, biomass_te)
table(binned_te$carbon)

image

Expected behaviour:

breaks <- quantile(biomass_tr$carbon, probs = seq(0, 1, length = 4 + 1))
table(cut(biomass_te$carbon, breaks = breaks))

image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions