yobx.sklearn.preprocessing.polynomial_features#
- yobx.sklearn.preprocessing.polynomial_features.sklearn_polynomial_features(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: PolynomialFeatures, X: str, name: str = 'polynomial_features') str[source]#
Converts a
sklearn.preprocessing.PolynomialFeaturesinto ONNX.The output is the matrix of all polynomial combinations of the input features up to the given degree. Each output feature corresponds to one row of
estimator.powers_, where each row defines the exponent for each input feature.The graph is built as follows:
X ──Unsqueeze(axis=1)──► X_3d (N, 1, F) │ ┌───────────┤ powers_3d │ (1, K, F) constant zero_mask_3d │ (1, K, F) constant bool │ │ Where(zero_mask_3d, 1.0, X_3d) ──► X_safe (N, K, F) │ Pow(X_safe, powers_3d) ──► powered (N, K, F) │ ReduceProd(axis=-1) ──► output (N, K)where K =
n_output_features_and F =n_features_in_.The
Whereguard ensures that0 ** 0 = 1(sklearn convention) is satisfied even when the input contains zeros: whenever the exponent is 0, the base is replaced by 1 before thePowoperation.- Parameters:
g – the graph builder to add nodes to
sts – shapes defined by scikit-learn
outputs – desired output names
estimator – a fitted
PolynomialFeaturesX – input tensor name
name – prefix for added node names
- Returns:
output tensor name