yobx.sklearn.multiclass.one_vs_one#

yobx.sklearn.multiclass.one_vs_one.sklearn_one_vs_one_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: OneVsOneClassifier, X: str, name: str = 'one_vs_one') str[source]#

Converts a sklearn.multiclass.OneVsOneClassifier into ONNX.

The converter replicates predict(), which is equivalent to decision_function() followed by argmax. For K classes there are K*(K-1)/2 binary sub-estimators, one for each pair (i, j) with i < j.

For each pair k = (i, j):

  • confidence_k = predict_proba_k[:, 1] — probability that class j wins.

  • binary_pred_k = (confidence_k >= 0.5) — 1 if class j wins, 0 if class i wins.

The vote and confidence accumulators for class c are:

vote_c      = Σ_{k: c==i} (1 − pred_k)  +  Σ_{k: c==j} pred_k
sum_conf_c  = Σ_{k: c==i} (−conf_k)      +  Σ_{k: c==j} conf_k

The continuous tie-breaking transform is:

transformed_conf_c = sum_conf_c / (3 * (|sum_conf_c| + 1))

The final per-class score is:

score_c = vote_c + transformed_conf_c

The predicted label is classes_[argmax(score)].

Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

  • outputs – desired output tensor names (label only; OvO has no predict_proba)

  • estimator – a fitted OneVsOneClassifier

  • X – name of the input tensor

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

Returns:

label tensor name

Raises:

NotImplementedError – when estimator.pairwise_indices_ is not None or when a sub-estimator does not expose predict_proba()