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.StackingClassifierinto 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 columnproba[:, 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
StackingClassifierX – 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.StackingRegressorinto ONNX.For each base estimator, the converter calls the registered converter using the
predictstack method, reshapes the 1-D predictions to(N, 1), and concatenates them into a meta-feature matrix of shape(N, n_estimators). Whenpassthrough=Truethe 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
StackingRegressorX – name of the input tensor
name – prefix used for names of nodes added by this converter
- Returns:
name of the output tensor