yobx.sklearn.multiclass.one_vs_rest#

yobx.sklearn.multiclass.one_vs_rest.sklearn_one_vs_rest_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: OneVsRestClassifier, X: str, name: str = 'one_vs_rest') str | Tuple[str, str][source]#

Converts a sklearn.multiclass.OneVsRestClassifier into ONNX.

The converter iterates over the fitted binary sub-estimators, calls the registered converter for each one to obtain per-class positive-class probabilities, stacks them into a score matrix, and then derives the final label and (optionally) the probability matrix.

Multiclass (len(estimators_) > 1):

X ──[sub-est 0 converter]──► proba_0 (Nx2) ──Slice[:, 1]──► pos_0 (Nx1)
X ──[sub-est 1 converter]──► proba_1 (Nx2) ──Slice[:, 1]──► pos_1 (Nx1)
...
                                         Concat(pos_0, pos_1, ..., axis=1)
                                                     │
                                                  scores (NxC)
                                                     │
                                            ReduceSum(axis=1) ──►  sum_
                                                     │
                                                Div(scores, sum_) ──► proba (NxC)
                                                     │
                                       ┌─────────────┘
                                   ArgMax(axis=1) ──Cast──Gather(classes) ──► label

Binary (len(estimators_) == 1):

X ──[sub-est 0 converter]──► proba_0 (Nx2) ──Slice[:, 1]──► pos (Nx1)
                                                  │
                                    Sub(1, pos) ──┤
                                          │       │
                                      neg (Nx1)   │
                  Concat(axis=1)──► proba (Nx2) ──┘
                       │
                     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 (label, or label + probabilities)

  • estimator – a fitted OneVsRestClassifier

  • 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 estimator.multilabel_ is True or when a sub-estimator does not expose predict_proba()