Explainable One-Class SVM

Machine Learning
Introduced by
Schölkopf, B. et al. (OCSVM); explainability layer via Lundberg & Lee (SHAP, 2017) and related works
Year
1999 (OCSVM); 2017–present (explainability integration)
Type
Anomaly/novelty detection with post-hoc or intrinsic explainability
Family
Machine learning

What does it do?

Explainable One-Class SVM combines the One-Class Support Vector Machine, a novelty detector that learns a boundary around normal data without labeled anomalies, with post-hoc explanation methods such as SHAP or LIME.

These methods attribute each anomaly score to individual input features, so an analyst can see which variables pushed an observation outside the learned boundary. The explanation layer describes the detector's output; it does not change the detector itself.

The intuition behind the method

A One-Class SVM learns a boundary around normal training examples in a high-dimensional kernel space, and any new point that falls outside that boundary is flagged as anomalous. The boundary itself is hard to read, so the model does not say which inputs caused a flag. The explainability layer is added after the boundary is fitted: SHAP or LIME splits each anomaly score into per-feature contributions. For example, an analyst might find that an unusually high reading on one sensor channel was the main reason an observation was flagged. This layer makes the decisions easier to inspect and document, but the flags themselves come from the One-Class SVM alone.

History

The One-Class SVM was introduced by Schölkopf and colleagues in 1999 as an extension of the support vector framework to novelty detection. SHAP was introduced by Lundberg and Lee in 2017, and the two methods have since been combined to produce per-observation explanations of One-Class SVM flags. The combination is an applied practice; the sources cited on this page describe the two components rather than the combined method.

When to use it

Choose Explainable One-Class SVM when the training data are mostly or entirely normal, with no labeled anomalies or only a handful, and when someone must be able to see which features drove a flag. Typical cases are fraud screening, equipment or device monitoring, and quality control, especially in settings where per-decision explanations are requested. Do not use it when labeled anomalies are plentiful, because a supervised classifier is usually the better choice. It is also a poor fit for very high-dimensional, sparse feature sets, where kernel distances become less informative, and for large training sets or real-time scoring with many features, where kernel computation and SHAP attribution become expensive.

Limitations and considerations

  • Training and memory cost grow quickly with the number of training samples because kernel methods work with pairwise kernel values. Very large datasets may require subsampling or a different detector.
  • Results depend strongly on the kernel and on nu. Poor choices produce either excessive false alarms or missed anomalies.
  • SHAP and LIME give approximate attributions. For kernel models with large background sets, the explanation step can be costly, and the attributions depend on the chosen background data. The background set should be a representative sample of normal training data, and its size and composition should be reported with the attributions.
  • In very high-dimensional spaces, distances under the kernel lose discriminative power, which weakens both the boundary and the attributions built on it.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Training requires only normal observations, so no labeled anomaly examples are needed.
  • The kernel allows the normal region to take complex nonlinear shapes that a linear boundary cannot represent.
  • SHAP or LIME turns the kernel boundary into per-feature, per-observation attributions that can be logged for review.
  • The parameter nu gives a direct handle on the expected outlier fraction. The kernel width is a second parameter that also needs to be set, so calibration is not reduced to a single choice.
  • Its per-observation explanations fit settings in which an analyst must justify each flag, such as audits in finance or medical device monitoring.

Applications

  • Network intrusion detection, where unusual traffic is flagged with per-feature explanations for security analysts.
  • Predictive maintenance, where abnormal sensor readings in manufacturing equipment are traced to the features behind each flag.
  • Patient monitoring, where deviations in physiological signals are flagged along with the features that contributed to the flag.
  • Transaction screening, where anomalous transactions are flagged with feature-level explanations that can be stored for compliance review.
  • Quality control, where defective products are detected using only examples of conforming items for training.

How it works

How it works

1

The input data are mapped implicitly into a high-dimensional reproducing kernel Hilbert space through a kernel function, most commonly the RBF kernel. The kernel lets the algorithm describe a nonlinear normal region without computing the transformed coordinates explicitly.

Formula
\phi: \mathcal{X} \to \mathcal{H} \text{ via kernel } K(x,x')
2

The One-Class SVM solves a quadratic program that fits a hyperplane in feature space separating the mapped training points from the origin. With the RBF kernel, this hyperplane corresponds to a closed boundary in input space that encloses the normal data, which is why the step carries the name fit-hypersphere. The parameter nu sets an upper bound on the fraction of training points treated as outliers. The kernel width must be chosen alongside nu, and together they control how tightly the boundary wraps the normal data.

Formula
\min_{w,\rho,\xi} \frac{1}{2}\|w\|^2 - \rho + \frac{1}{\nu n}\sum_i \xi_i
3

For each new observation, the decision function measures where it lies relative to the learned boundary. Observations on the normal side of the threshold are classified as normal, and those on the other side are flagged as anomalies or novelties. Within one fitted model, the decision value orders observations by their position relative to the boundary. It is not a calibrated probability and should not be compared across models or thresholds without recalibration.

Formula
f(x) = \text{sign}(w \cdot \phi(x) - \rho)
4

A post-hoc explanation method, typically SHAP (SHapley Additive exPlanations) or LIME, is applied to the trained decision function. For a given observation, SHAP estimates each feature's contribution to the anomaly score by averaging its marginal effect over combinations of the other features, giving a signed value per feature for each observation.

5

SHAP or LIME attributions are aggregated across the flagged observations to rank features by how much they contribute to detected anomalies. The ranking can direct domain experts to the dimensions most worth investigating and can support root-cause analysis. It is a summary of the model's behaviour, not a verified diagnosis.

Common pitfalls

  • Training on data that already contains anomalies, which contaminates the learned normal boundary.
  • Choosing nu without domain knowledge. Setting it too small causes the model to ignore real anomalies; setting it too large produces excessive false alarms.
  • Treating SHAP explanations as causal. They describe feature contributions to the model's score, not causal pathways in the data-generating process.
  • Skipping feature scaling before fitting, since the RBF kernel is distance-based and sensitive to differences in feature magnitude.
  • Conflating explainability with interpretability. Post-hoc SHAP values explain the model's output but do not simplify the underlying kernel decision function.
  • Using categorical features without numerical encoding. The encoding choice changes the kernel distances, so results on mixed-type data may be unreliable.

Frequently asked questions

Do I need labeled anomaly examples to train an Explainable One-Class SVM?

No. The One-Class SVM is trained only on normal data. If labeled anomalies are available, a supervised classifier or a semi-supervised approach is usually the better choice.

Which explainability method works best with One-Class SVM?

KernelSHAP is model-agnostic and can be applied to any kernel, but it can be slow on large training sets. LIME is typically faster but is a local surrogate method without the Shapley-based properties that KernelSHAP inherits from Lundberg and Lee (2017). For small to medium datasets, KernelSHAP is often preferred, and the stability of its attributions should be checked on the chosen background set.

How do I choose the nu hyperparameter?

Nu is an upper bound on the fraction of training samples that may lie outside the boundary (treated as outliers). Set it near your domain-informed expectation of the contamination rate. Standardise the features first, then choose the kernel width by a grid search. Check the flag rate on held-out normal data and on any known anomalies: a high flag rate on normal data means the boundary is too tight, and missed known anomalies mean it is too loose.

How does Explainable One-Class SVM differ from Isolation Forest with SHAP?

Isolation Forest is generally faster and scales more easily to large datasets. A kernel One-Class SVM can model smoother and more complex normal regions, but it depends more on kernel and scaling choices. Both can be explained post hoc with SHAP in a similar way.

Can SHAP values from an OCSVM be trusted for high-stakes decisions?

SHAP values accurately attribute contributions to the model's anomaly score, but the model may have absorbed spurious patterns from its training data. Combine the attributions with domain expert review and validate on held-out data before relying on them in high-stakes settings.

Related methods

Sources

  1. Schölkopf, B., Williamson, R., Smola, A., Shawe-Taylor, J., & Platt, J. (1999). Support vector method for novelty detection. Advances in Neural Information Processing Systems, 12, 582–588.

    Open publication reference
  2. Lundberg, S. M., & Lee, S.-I. (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems, 30.

    Open publication reference