yobx.sklearn.preprocessing.one_hot_encoder#
- yobx.sklearn.preprocessing.one_hot_encoder.sklearn_one_hot_encoder(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: OneHotEncoder, X: str, name: str = 'one_hot_encoder') str[source]#
Converts a
sklearn.preprocessing.OneHotEncoderinto ONNX.The converter handles all standard configurations of
OneHotEncoder:Multiple features – each feature column is processed independently and the resulting one-hot blocks are concatenated along the feature axis.
Drop – when
dropis notNone(e.g.'first'or'if_binary'), the converter uses the fitteddrop_idx_attribute to skip the dropped category column for each feature.Unknown handling – because the encoding is implemented via element-wise comparisons (
Equal), samples with categories that were not seen during training produce an all-zero row for that feature, matchinghandle_unknown='ignore'behaviour.
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(float) ──► (N×K) float │ [Gather(keep_idx)] (only when drop≠None) │ feature_i_out (N×K')Each
feature_i_outis concatenated alongaxis=1to form the final output.- Parameters:
g – the graph builder to add nodes to
sts – shapes defined by scikit-learn
outputs – desired output tensor names
estimator – a fitted
OneHotEncoderX – name of the input tensor
name – prefix used for names of nodes added by this converter
- Returns:
name of the output tensor
- Raises:
ValueError – when no output columns remain after applying
drop