yobx.sklearn.covariance.elliptic_envelope#

yobx.sklearn.covariance.elliptic_envelope.sklearn_elliptic_envelope(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: EllipticEnvelope, X: str, name: str = 'elliptic_envelope') str | Tuple[str, str][source]#

Converts a sklearn.covariance.EllipticEnvelope into ONNX.

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().

The decision function is computed as:

\text{decision}(x) = -\lVert x - \mu \rVert^2_{\Sigma^{-1}} - \text{offset}

where \mu is location_, \Sigma^{-1} is precision_, and offset_ is the threshold learned during fitting. The squared Mahalanobis distance is:

d^2(x) = (x - \mu)^\top \, \Sigma^{-1} \, (x - \mu)
        = \sum_j \bigl[(x - \mu) \Sigma^{-1}\bigr]_j \cdot (x - \mu)_j

Full graph structure:

X (N, F)
  │
  └─ Sub(location_) ──► X_centered (N, F)
       │
       ├─ MatMul(precision_) ──► X_prec (N, F)
       │                              │
       └──────────────────── Mul ──► X_prec_centered (N, F)
                                      │
                           ReduceSum(axis=1) ──► mahal_sq (N,)
                                      │
                                   Neg ──► score_samples (N,)
                                      │
                           Sub(offset_) ──► decision (N,) [scores output]
                                      │
                     GreaterOrEqual(0) ──► mask (N,)
                                      │
                      Where(1, -1) ──► label (N,) [label output]
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 EllipticEnvelope

  • X – input tensor name

  • name – prefix for added node names

Returns:

tuple (label, scores)