yobx.sklearn.svm.one_class_svm#

yobx.sklearn.svm.one_class_svm.sklearn_one_class_svm(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: OneClassSVM, X: str, name: str = 'one_class_svm') str | Tuple[str, str][source]#

Converts a sklearn.svm.OneClassSVM into ONNX using the SVMRegressor operator from the ai.onnx.ml domain.

Supported kernels: 'linear', 'poly', 'rbf', 'sigmoid'. Callable kernels are not supported.

The converter produces two outputs:

  • label: the outlier predictions (1 for inlier, -1 for outlier), equivalent to predict().

  • scores: the decision function values, equivalent to decision_function().

Note

The SVMRegressor operator only supports float32 input. When the input tensor is float64, it is cast to float32 before the SVM node and the resulting scores are cast back to float64 afterwards. This may introduce small numerical differences compared to running inference with float64 arithmetic.

Graph structure:

X (float64) ──Cast(float32)──► X_f32
        │
X (float32) ──────────────────────────┐
                                      ▼
                        SVMRegressor(one_class=0) ──► raw_scores (N, 1) [float32]
                                      │
                                 Reshape ──► scores_f32 (N,) [float32]
                                      │
                      [Cast to float64 if input was float64]
                                      │
                                 scores (N,) [input dtype]
                                      │
                           GreaterOrEqual(0) ──► mask (N,)
                                      │
                           Where(1, -1) ──► label (N,)
Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • outputs – desired output names; outputs[0] receives the predicted labels and outputs[1] (if present) receives the decision function values

  • estimator – a fitted OneClassSVM

  • X – input tensor name

  • name – prefix for added node names

Returns:

label tensor name, or tuple (label, scores)