yobx.sklearn.ensemble.stacking#

yobx.sklearn.ensemble.stacking.sklearn_stacking_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: StackingClassifier, X: str, name: str = 'stacking_classifier') str | Tuple[str, str][source]#

Converts a sklearn.ensemble.StackingClassifier into ONNX.

For each base estimator, the converter dispatches on the stack_method_ attribute to collect meta-features:

  • predict_proba — binary problem (len(classes_) == 2): only the positive-class column proba[:, 1:] is kept, giving shape (N, 1); multiclass: all probability columns are kept.

  • predict — the 1-D label output is reshaped to (N, 1) and cast to the input float dtype.

Graph structure (binary example):

X ──[est 0 converter]──► proba_0 (N,2) ──Slice[:,1:]──► (N,1)──┐
X ──[est 1 converter]──► proba_1 (N,2) ──Slice[:,1:]──► (N,1)──┤
...                                                              │
                                            Concat(axis=1) ─────► meta (N, n_est)
                                                                 │
                                  [passthrough X concat] ────────┤ (optional)
                                                                 │
                                      [final estimator] ─────────► label [, proba]
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

  • outputs – desired output tensor names (label, or label + probabilities)

  • estimator – a fitted StackingClassifier

  • X – name of the input tensor

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

Returns:

label tensor name, or tuple (label, probabilities)

Raises:

NotImplementedError – when a stack_method_ entry other than 'predict_proba' or 'predict' is encountered

yobx.sklearn.ensemble.stacking.sklearn_stacking_regressor(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: StackingRegressor, X: str, name: str = 'stacking_regressor') str[source]#

Converts a sklearn.ensemble.StackingRegressor into ONNX.

For each base estimator, the converter calls the registered converter using the predict stack method, reshapes the 1-D predictions to (N, 1), and concatenates them into a meta-feature matrix of shape (N, n_estimators). When passthrough=True the original features are appended before the final estimator is applied.

Graph structure:

X ──[est 0 converter]──► pred_0 (N,) ──Reshape(N,1)──┐
X ──[est 1 converter]──► pred_1 (N,) ──Reshape(N,1)──┤
...                                                    │
                                      Concat(axis=1) ─►meta (N, n_est)
                                                       │
                           [passthrough X concat] ─────┤ (optional)
                                                       │
                               [final estimator] ──────► predictions
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

  • outputs – desired output tensor names

  • estimator – a fitted StackingRegressor

  • X – name of the input tensor

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

Returns:

name of the output tensor