yobx.sklearn.category_encoders.basen_encoder#

yobx.sklearn.category_encoders.basen_encoder.category_encoders_basen_encoder(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: BaseNEncoder, X: str, name: str = 'basen_encoder') str[source]#

Converts a category_encoders.BaseNEncoder into ONNX.

Each categorical column is replaced by a block of digit columns that encode the ordinal index of the category value in base N (most significant digit first). Non-categorical columns pass through unchanged.

X  ──col_j (categorical, K cats)──►  digit_0 (MSD)  (N, 1)
                                      digit_1         (N, 1)
                                      ...
                                      digit_D (LSD)   (N, 1)
                                      Concat(digit_0 ... digit_D, axis=1)──► block (N, D)

X  ──col_k (numerical)──►  unchanged  (N, 1)

Concat(all blocks and pass-through cols, axis=1)──► output (N, F_out)

where D is the number of base-N digits required to represent the largest ordinal and F_out is the total number of output columns.

The conversion reads the fitted mapping attribute (ordinal → digit row) together with the ordinal_encoder attribute (category value → ordinal) to determine the per-column digit blocks.

Unknown categories (values not seen during training):

  • handle_unknown='value' (default): all digit columns for that row are 0.

  • handle_unknown='return_nan': all digit columns for that row are NaN.

Missing values (NaN inputs):

  • handle_missing='value' (default): all digit columns for that row are 0.

  • handle_missing='return_nan': all digit columns for that row are NaN.

Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • outputs – desired output tensor names

  • estimator – a fitted BaseNEncoder

  • X – name of the input tensor (shape (N, F))

  • name – prefix used for names of nodes added by this converter

Returns:

name of the output tensor

Raises:

AssertionError – if estimator is not fitted or type info is missing from the graph