yobx.sklearn.linear_model.linear_classifier#
- yobx.sklearn.linear_model.linear_classifier.sklearn_linear_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: RidgeClassifier | SGDClassifier | Perceptron, X: str, name: str = 'linear_classifier') str | Tuple[str, str][source]#
Converts a sklearn linear classifier into ONNX.
Handles both classifiers that expose
predict_proba()(e.g.SGDClassifierwithloss='log_loss'or'modified_huber') and those that do not (e.g.RidgeClassifier).Binary classification (
len(classes_) == 2):X ──Gemm(coef, intercept)──► decision (Nx1) │ Flatten ──► decision_1d (N,) │ ┌─────────┴──────────┐ │ (if proba) Greater(0) Sigmoid ──Sub(1,·)──Concat │ │ Cast(INT64) proba (Nx2) │ Gather(classes) ──► labelMulticlass (
len(classes_) > 2):X ──Gemm(coef, intercept)──► decision (NxC) │ ┌─────────┴──────────┐ │ (if proba) ArgMax Softmax ──► proba (NxC) │ Cast(INT64) │ Gather(classes) ──► label- Parameters:
g – the graph builder to add nodes to
sts – shapes defined by scikit-learn
outputs – desired output names; one name (label only) or two names (label + probabilities) depending on
get_output_names()estimator – a fitted linear classifier
X – input tensor name
name – prefix for added node names
- Returns:
label tensor name, or tuple
(label, probabilities)when the estimator supportspredict_proba()