yobx.sklearn.ensemble.bagging#

yobx.sklearn.ensemble.bagging.sklearn_bagging_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: BaggingClassifier, X: str, name: str = 'bagging_classifier') str | Tuple[str, str][source]#

Converts a sklearn.ensemble.BaggingClassifier into ONNX.

Probabilities from all sub-estimators are averaged (soft aggregation) and the winning class is determined by an argmax over the averaged probability vector. Each sub-estimator is applied to the feature subset recorded in estimators_features_.

Graph structure (two sub-estimators as an example):

X ──Gather(cols_0)──[sub-est 0]──► (_, proba_0) (N, C)
X ──Gather(cols_1)──[sub-est 1]──► (_, proba_1) (N, C)
        Unsqueeze(axis=0) ──► proba_0 (1, N, C), proba_1 (1, N, C)
            Concat(axis=0) ──► stacked (E, N, C)
                ReduceMean(axis=0) ──► avg_proba (N, C)
                    ArgMax(axis=1) ──Cast──Gather(classes_) ──► label
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

  • outputs – desired output tensor names; two entries for (label, probabilities), one entry for label only

  • estimator – a fitted BaggingClassifier

  • 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)

yobx.sklearn.ensemble.bagging.sklearn_bagging_regressor(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: BaggingRegressor, X: str, name: str = 'bagging_regressor') str[source]#

Converts a sklearn.ensemble.BaggingRegressor into ONNX.

Each sub-estimator’s predictions (computed on the feature subset recorded in estimators_features_) are averaged to produce the final prediction.

Graph structure (two sub-estimators as an example):

X ──Gather(cols_0)──[sub-est 0]──► pred_0 (N,)
X ──Gather(cols_1)──[sub-est 1]──► pred_1 (N,)
                   Reshape(N,1) ──► pred_0, pred_1
                       Concat(axis=1) ──► stacked (N, E)
                           ReduceMean(axis=1) ──► predictions (N,)
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

  • outputs – desired output tensor names (one entry: predictions)

  • estimator – a fitted BaggingRegressor

  • X – name of the input tensor

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

Returns:

name of the predictions output tensor