yobx.sklearn.preprocessing.ordinal_encoder#

yobx.sklearn.preprocessing.ordinal_encoder.sklearn_ordinal_encoder(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: OrdinalEncoder, X: str, name: str = 'ordinal_encoder') str[source]#

Converts a sklearn.preprocessing.OrdinalEncoder into ONNX.

Each feature column is independently mapped from its category value to an integer ordinal (0-based position in the sorted categories_ list). Unknown categories and missing (NaN) inputs are handled via Where overrides.

The conversion for a single feature i with categories [c_0, c_1, …, c_{K-1}] is:

X ──Gather(col i)──► col_i  (N×1)
                        │
        Equal(col_i, [[c_0, …, c_{K-1}]])  ──► (N×K) bool
                        │
                Cast(int64)  ──► (N×K) int64
                        │
      ┌─────────────────┴──────────────────┐
      │                                     │
ArgMax(axis=1)                    ReduceMax(axis=1)
(N×1) int64 ordinal           (N×1) int64  any-match flag
      │                                     │
Cast(float)                       Cast(bool)
      └──── Where(any_match, ordinal, unk) ─┘
                        │
                Where(IsNaN(col_i), nan_val, …)
                        │
                 feature_i_out  (N×1)

All per-feature tensors are concatenated along axis=1.

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

  • sts – shapes defined by scikit-learn

  • outputs – desired output tensor names

  • estimator – a fitted OrdinalEncoder

  • X – name of the input tensor

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

Returns:

name of the output tensor