- Introduced by
- Scholkopf, B., Platt, J. C., Smola, A. J., Williamson, R. C.
- Year
- 1999–2001
- Type
- Anomaly / novelty detection (unsupervised)
- Family
- Machine learning
What does it do?
One-class SVM is an unsupervised method for novelty and anomaly detection.
It learns a boundary around normal training data in a kernel-induced feature space and flags new observations that fall outside that boundary. Introduced by Scholkopf and colleagues and published in Neural Computation in 2001, it extends the support vector algorithm to unlabelled data, so no labelled anomalies are needed.
The intuition behind the method
Think of fitting a boundary around the training points in a space transformed by a kernel function, and treating anything outside that boundary as a possible anomaly. The parameter nu controls how generous the boundary is. A small nu requires almost all training points to lie on the normal side, so the boundary stays wide; a larger nu allows more training points outside, so the boundary tightens. Because the kernel makes the boundary non-linear in the original input space, the method can describe curved or irregular regions of normality that a simple distance threshold would not capture.
History
The one-class SVM was introduced by Scholkopf and colleagues and published in Neural Computation in 2001 as 'Estimating the support of a high-dimensional distribution'. The formulation extends the support vector algorithm to unlabelled data by estimating a function that is positive on a simple region capturing most of the data and negative on its complement. Tax and Duin's Support Vector Data Description (Machine Learning, 54(1), 2004) is a closely related approach that encloses the data in a hypersphere in feature space.
When to use it
Choose One-class SVM when labelled anomalies are unavailable or scarce, the observations are described by continuous numeric features, and normal behaviour has a complex, non-linear shape that simple thresholds or distance rules may not capture. Typical settings include fraud, intrusion and industrial fault monitoring, though the choice should be tested on the data at hand. It suits moderately sized training sets, because the quadratic program becomes costly as the number of training observations grows. Avoid it when the training set is very large, when the features are predominantly categorical, or when fast and interpretable rules are the priority; Isolation Forest, Local Outlier Factor and threshold-based statistical models are the natural alternatives to compare against.
Limitations and considerations
- The quadratic program has a training cost that grows rapidly with the number of training observations (O(n^2) to O(n^3)), so large datasets are expensive to fit.
- Results depend strongly on the kernel and its parameters. For the RBF kernel, gamma sets the radius of influence, and poor values produce a boundary that is either too tight or too loose.
- The method assumes the training set is essentially normal. Contamination shifts the boundary to enclose the anomalous training points, so similar anomalies at test time may be accepted as normal.
- The decision value is not a calibrated probability and cannot be read directly as the likelihood of an anomaly.
- Explaining why a specific point falls outside the boundary is difficult without additional post-hoc tools.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Needs only normal training observations, so it applies when anomaly labels do not exist.
- A kernel such as the RBF lets the boundary follow curved or multi-modal regions of normal data, because only inner products in the feature space are evaluated.
- The parameter nu has a direct meaning as an upper bound on the fraction of training points treated as outliers, which makes it easier to set from domain knowledge than an arbitrary penalty weight.
- The continuous decision value can be ranked and thresholded, so the cut-off can be chosen to reflect the relative costs of false alarms and missed anomalies.
Applications
- Network intrusion detection, flagging traffic patterns not seen during normal operation.
- Industrial condition monitoring, flagging sensor readings that deviate from healthy-state profiles.
- Fraud screening, where fraudulent examples are too few to train a supervised classifier.
- Medical screening, flagging measurements that fall outside the distribution of healthy reference data.
How it works
How it works
All training observations are mapped into a high-dimensional (potentially infinite-dimensional) feature space via a kernel function such as the radial basis function (RBF). The inner products in that space can be evaluated without computing the mapping explicitly, which makes the approach tractable even for complex boundaries.
Formula
\phi: \mathcal{X} \to \mathcal{F}A quadratic program finds a hyperplane in the feature space that separates the mapped training data from the origin with maximum margin. The objective is minimised subject to <w, phi(x_i)> >= rho - xi_i and xi_i >= 0 for every training point, with 0 < nu <= 1. The parameter nu is an upper bound on the fraction of training points treated as outliers and a lower bound on the fraction of support vectors. The practitioner therefore has direct control over how many training points the boundary may exclude.
Formula
\min_{w,\rho,\xi}\; \tfrac{1}{2}\|w\|^2 - \rho + \tfrac{1}{\nu n}\sum_i \xi_i \quad \text{s.t.}\; \langle w, \phi(x_i)\rangle \ge \rho - \xi_i,\; \xi_i \ge 0,\; 0<\nu\le 1The learned hyperplane defines a signed decision function f(x). Points with positive values (on the side of the hyperplane away from the origin, above the offset rho) are classified as normal; points with negative values are flagged as anomalies or novelties. The raw decision value can also serve as a continuous anomaly score for ranking.
Formula
f(x) = \text{sgn}\bigl(\langle w, \phi(x)\rangle - \rho\bigr)Choosing nu is the key modelling decision. Because nu is an upper bound on the training outlier fraction rather than an exact estimate of contamination, choose it from domain estimates of how atypical the training data may be. Then check on held-out normal observations what fraction is flagged, and adjust nu (and the kernel parameters) so that this fraction is acceptable. Tuning uses only normal data; no anomaly labels are required.
In deployment, the default rule is the sign of f(x). The threshold can instead be set as a quantile of decision values on held-out normal data; for example, the 5th percentile of normal scores gives roughly a 5% false-alarm rate. Moving the threshold trades false alarms against missed anomalies, which suits applications where the two errors carry different costs.
Common pitfalls
- Training on data that contains undetected anomalies, which the boundary then treats as normal.
- Setting nu without reference to the plausible fraction of atypical training points, which leads either to many false alarms or to missed anomalies.
- Keeping the default RBF gamma without tuning, so that the boundary flags almost every new point or almost none.
- Applying the exact solver to very large datasets without considering approximate or scalable alternatives.
- Reporting only a binary flag without inspecting the score distribution, which is needed to choose a sensible threshold.
Frequently asked questions
What is the difference between One-class SVM and Isolation Forest for anomaly detection?
One-class SVM learns an explicit kernel-based boundary around normal data, which suits continuous features with curved regions of normality, but its training cost grows quickly with the number of observations. Isolation Forest is a tree-based alternative that does not require a kernel and is typically faster to fit on large datasets. Comparing both on held-out normal data and any known anomalies is the practical way to decide between them.
How should I choose the nu parameter?
Nu is an upper bound on the fraction of training points treated as outliers and a lower bound on the fraction of support vectors; it is not an exact estimate of contamination. Choose a starting value from your domain estimate (for example nu=0.05 if you expect only a few percent of atypical training points), then check what fraction of held-out normal examples is flagged and adjust accordingly.
What kernel should I use?
The RBF (Gaussian) kernel is the usual starting point for continuous numeric data. Its gamma parameter controls the radius of influence. Because no anomaly labels are available, tune gamma and nu using held-out normal data, for example by examining the fraction of normal points accepted over a log-spaced grid of gamma values, rather than by label-based cross-validation. A linear kernel is faster but restricts the boundary to a hyperplane.
Can One-class SVM handle categorical features?
Not directly. Categorical variables must be encoded numerically before use, which can distort distances in the kernel. For datasets dominated by categorical features, consider alternatives such as Isolation Forest.
My training set may contain some anomalies. Does that break the model?
Contamination in the training data shifts the boundary to include the anomalous points, so similar anomalies may later be accepted as normal. The nu parameter tolerates some training points outside the boundary, but it does not remove the need for clean normal data. If contamination is suspected, screen the training data with a separate detector, remove the most suspicious points, and check whether the boundary changes.
Related methods
Sources
Scholkopf, B., Platt, J. C., Shawe-Taylor, J., Smola, A. J., & Williamson, R. C. (2001). Estimating the support of a high-dimensional distribution. Neural Computation, 13(7), 1443–1471.
Open DOI referenceTax, D. M. J., & Duin, R. P. W. (2004). Support vector data description. Machine Learning, 54(1), 45–66.
Open DOI reference