cursus.processing.categorical.numerical_categorical_processor

Numerical Categorical Processor for Converting Numbers to Categories

This module provides atomic conversion of numerical values to categorical labels. Extracted from TSA numerical categorization requirements.

class NumericalCategoricalProcessor(binning_strategy='equal_width', n_bins=5, bin_edges=None, thresholds=None, labels=None, columns=None)[source]

Bases: Processor

Converts numerical values to categorical labels using binning or thresholds.

Extracted from TSA str(int(float(cur_var))) conversion patterns.

Parameters:
  • binning_strategy (str) – ‘equal_width’, ‘equal_frequency’, ‘custom’, ‘threshold’

  • n_bins (int) – Number of bins for equal_width/equal_frequency

  • bin_edges (List[float] | None) – Custom bin edges for ‘custom’ strategy

  • thresholds (List[float] | None) – Threshold values for ‘threshold’ strategy

  • labels (List[str] | None) – Custom labels for categories

  • columns (List[str] | None) – Specific columns to process

fit(data)[source]

Learn binning parameters from data.

For equal_width / equal_frequency the bin edges are LEARNED here. For custom / threshold the bins come from the constructor params (bin_edges / thresholds) and there is nothing to learn — but we still validate the required param is present so is_fitted is never set True for a strategy that has no usable bins (which previously caused a silent mis-binning at transform time).

process(input_data)[source]

Apply numerical to categorical conversion

get_bin_info(column=None)[source]

Get binning information

get_config()[source]

Return processor configuration