yobx.sklearn.calibration.calibrated_classifier#

yobx.sklearn.calibration.calibrated_classifier.sklearn_calibrated_classifier_cv(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: CalibratedClassifierCV, X: str, name: str = 'calibrated_classifier') Tuple[str, str][source]#

Converts a sklearn.calibration.CalibratedClassifierCV into ONNX.

Both method='sigmoid' (Platt scaling) and method='isotonic' are supported, for binary and multiclass problems. Probabilities from all cross-validation folds are averaged to produce the final estimate.

The raw predictions fed to the calibrators mirror sklearn’s _get_response_values priority: decision_function is used when the base estimator has coef_ and intercept_ attributes (all linear models), and predict_proba is used otherwise (e.g. RandomForestClassifier).

Sigmoid calibration:

predictions (N,)  ──Mul(a)──Add(b)──Neg──Sigmoid──►  cal_prob (N,)

Isotonic calibration — piecewise-linear mapping via numpy.interp():

T (N,)  ──GreaterOrEqual(X_thresh)──ReduceSum──► bin_idx
                                                      │
         Gather(X_thresh, Y_thresh) ──► x0,x1,y0,y1 (N,)
                                                      │
         y0 + (T-x0)*(y1-y0)/(x1-x0) ──Clip──►  cal (N,)

Binary (two classes):

X ──[base estimator]──► predictions (N,)  [decision or pos-class prob]
                                │
                 [calibrator_0]──► cal_pos (N,)
                                │
              [1-cal_pos, cal_pos] ──► fold_proba (N,2)

Multiclass (C classes):

X ──[base estimator]──► predictions (N,C)  [decision or proba]
    predictions[:,k] ──[calibrator_k]──► cal_k (N,)   (k=0..C-1)
                  ──Concat──ReduceSum/Div──► fold_proba (N,C)

Fold probabilities are averaged:

fold_proba_0 (1,N,C)
fold_proba_1 (1,N,C)  ──Concat(axis=0)──ReduceMean(axis=0)──► (N,C)
...
    ArgMax(axis=1)──Cast──Gather(classes_)──► label (N,)
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes and types defined by scikit-learn

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

  • estimator – a fitted CalibratedClassifierCV

  • X – name of the input tensor

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

Returns:

tuple (label_result_name, proba_result_name)

Raises:

NotImplementedError – if the base estimator has a decision_function but is not a linear model with coef_ / intercept_ (e.g. SVC without probability=True)