A one-class SVM (one-class support vector machine) is a kernel method that learns a boundary enclosing the normal data from examples of a single class and labels new points outside that boundary as anomalies. In anomaly detection, it is the classic model for novelty detection: it is trained on data assumed to be clean and then scores unseen observations by how far they fall from the learned region.
The method was introduced by Schölkopf and colleagues around 2001. It remains a standard baseline in libraries such as scikit-learn and PyOD because it handles nonlinear, multimodal normal behavior with a small number of support vectors and a well-understood optimization problem.
How a one-class SVM separates normal data from the origin
The one-class SVM maps each input through a kernel feature map into a high-dimensional space and then finds a hyperplane that separates the data from the origin with maximum margin. Points on the data side of the hyperplane are considered normal; points on the origin side are flagged as outliers.
Training solves a convex quadratic program. It minimizes the squared norm of the weight vector, minus an offset called rho, plus a penalty on slack variables scaled by 1 divided by nu times n. The solution depends only on a subset of training points, the support vectors, so the decision function is a weighted sum of kernel evaluations against them.
The resulting decision function returns a signed score: positive inside the learned region and negative outside. Its magnitude acts as an anomaly score, although it is not a calibrated probability. The main components are summarized below.
| Component | Role | Practical note |
|---|---|---|
| Kernel function | Defines similarity and the shape of the boundary | RBF is the usual default |
| Support vectors | Training points that define the boundary | Their count grows with nu |
| Offset rho | Position of the separating hyperplane | Learned during training |
| Decision function | Signed distance to the boundary | Threshold at zero by default |
| Slack variables | Allow some training points outside | Control robustness to contamination |
The nu and gamma parameters
Two hyperparameters dominate the behavior of a one-class SVM with an RBF kernel. The parameter nu lies between 0 and 1 and has a precise interpretation: it is an upper bound on the fraction of training outliers and a lower bound on the fraction of support vectors. Setting nu to 0.05 therefore lets about 5 percent of training points fall outside the boundary.
The kernel width gamma controls how local the boundary is. A large gamma produces tight, wiggly regions around individual points, while a small gamma gives a smooth, almost elliptical envelope. The table describes typical effects.
| Setting | Boundary shape | Typical risk |
|---|---|---|
| Low nu (0.01) | Encloses almost all training points | Misses anomalies hidden in training data |
| High nu (0.2) | Excludes a larger share of points | Many false alarms on normal data |
| Low gamma | Smooth and broad region | Underfits multimodal normal behavior |
| High gamma | Tight islands around samples | Overfits and rejects valid new points |
Tuning is difficult because labeled anomalies are usually scarce. Practitioners set nu near the expected contamination rate and choose gamma with heuristics such as 1 divided by the number of features times the feature variance, then validate on a small labeled holdout when one exists.
How it compares with other anomaly detectors
The one-class SVM is closely related to support vector data description, which encloses the data in a minimum-volume hypersphere; with an RBF kernel the two formulations give equivalent solutions. It differs more sharply from tree-based and density-based detectors.
| Method | Core idea | Scales to large data | Main strength |
|---|---|---|---|
| One-class SVM | Kernel boundary around normal data | Poorly, about quadratic in samples | Flexible smooth boundaries |
| Isolation forest | Anomalies isolate in few random splits | Well | Fast with little tuning |
| Local outlier factor | Compares local density with neighbors | Moderately | Detects local anomalies |
| Elliptic envelope | Robust Gaussian covariance fit | Well | Simple for unimodal data |
| Deep SVDD | Neural network maps data into a hypersphere | Well with GPUs | Handles images and raw signals |
The one-class SVM suits semi-supervised anomaly detection, where the training set contains only normal behavior. In fully unsupervised settings with unknown contamination, isolation forests are often more robust and much faster.
Practical use and preprocessing
Because the RBF kernel relies on Euclidean distances, feature scaling is mandatory. Standardization or robust scaling prevents one feature with large units from dominating the boundary. Categorical inputs need encoding, and high-dimensional data often benefits from PCA or learned embeddings before training.
- Industrial monitoring: vibration and temperature features from machines running in a known healthy state.
- Network security: flow statistics from normal traffic to flag unusual connections.
- Quality inspection: embeddings from a pretrained vision model of defect-free parts.
- Fraud screening: behavioral features from verified legitimate customers.
For large datasets, scikit-learn offers SGDOneClassSVM combined with a kernel approximation such as Nystroem features. This linear-time variant trades some boundary precision for the ability to train on millions of samples.
Limitations and common mistakes
The method has known weaknesses that experienced practitioners watch for. Training cost grows between quadratically and cubically with the number of samples, the scores are not probabilities, and performance degrades in very high dimensions where distances lose contrast.
| Mistake | Consequence | Correction |
|---|---|---|
| Unscaled features | Boundary driven by one variable | Standardize every feature |
| Contaminated training data | Anomalies absorbed as normal | Clean data or raise nu slightly |
| Default gamma on wide data | Overly tight or loose region | Tune gamma on a validation set |
| Treating scores as probabilities | Misleading alert thresholds | Calibrate thresholds on labeled cases |
| Training on raw images | Meaningless pixel distances | Use embeddings or Deep SVDD |
A frequent misconception is that a one-class SVM learns what anomalies look like. It learns only the shape of normal data, so any genuine change in normal behavior, such as a new product line or a seasonal shift, will be flagged until the model is retrained on updated data.
The short version
A one-class SVM learns what normal looks like. It sees only good examples during training. Then it draws a flexible fence around them.
Anything that lands outside the fence is suspicious. Think of a security guard who knows every regular visitor. A stranger stands out at once, even if the guard has never seen that stranger before. The method works the same way with data.
Where it makes a difference
A manufacturer monitors 40 pumps with accelerometers. Engineers collect three months of vibration data from pumps known to be healthy and compute 24 spectral features per one-minute window. They standardize the features and train a one-class SVM with an RBF kernel and nu set to 0.02.
In operation, each new window receives a decision score. When one pump shows negative scores for six consecutive hours, technicians inspect it and find early bearing wear. The repair happens during a planned stop instead of after a failure, and the model raises only a few false alarms per month across the whole fleet.