Handle Variable Discretisation

Feature-engine, a Python library for feature engineering

1 min read

Published Oct 3 2025


10
0
0
0

Feature EngineeringFeature-engineMachine LearningPandasPythonscikit-learnTransformers

This technique consists of transforming continuous numerical variables into discrete variables. Often referred to as binning as it creates bins to group values together.


Equal Frequency

It divides continuous numerical variables into contiguous equal frequency intervals, intervals containing approximately the same proportion of observations.


Parameters:

  • q : quantities - the number of equal frequency intervals.
eqf = EqualFrequencyDiscretiser(q=5, variables=['target']

This will create 5 bins of values. You can look at the calculated bins by looking at eqf.binner_dict_ which will show something like {'target': [-inf, 1.072, 1.573, 2.094, 2.9, inf]}






Equal Width

This technique divides continuous numerical variables into intervals of the same width. Each bin will probably have different counts.


Parameters:

  • bins : The number of equal width bins required.
ewd = EqualWidthDiscretiser(bins=6, variables=['target'])

This will create 6, equal width bins. The bin ranges can be viewed by looking at ewd.binner_dict_ which will show something like {'target': [-inf, 0.9583266666666665, 1.7666633333333333, 2.5749999999999997, 3.383336666666666, 4.191673333333333, inf]}






Arbitrary Discretiser

It divides continuous range intervals, which limits are determined by the user.


Parameters:

  • binning_dict - A dictionary object with the column and the user defined bin intervals.
ad = ArbitraryDiscretiser(binning_dict={'target':[0, 2, 4, 6, np.inf]})
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact