A one-class support vector machine (OCSVM) learns what one class of observations looks like, usually from normal training data. It draws a decision boundary around most of those observations while trying to keep the boundary tight. A later observation outside the boundary is a candidate novelty, not automatically a meaningful anomaly. section 5.4 section 5.8
Think of a simple one-class model that stores the minimum and maximum of its training values: a new value outside that range fails its test for normality. OCSVM applies the same basic idea with a more flexible boundary. It can leave some training points outside that boundary, and some unusual new points can fall inside it. section 5.4
A practical scikit-learn workflow is:
- Prepare a training sample that is as clean as possible, and keep separate data for testing. Available normal labels can help filter the training rows. section 5.4.1
- Create a `OneClassSVM`, fit it on the training data, then call `predict()` and `score_samples()` on the test data. section 5.4.1
- Check results rather than trusting the boundary alone. Kernel-related parameters can be difficult to tune, and different detectors may prioritize different records. section 5.4.1 section 5.0
Network-traffic test
In a KDD Cup dataset example, known labels identify normal records for a small training sample. The fitted OCSVM scores a separate test set and reaches an AUROC of 0.999. Even training without filtering achieves about 0.98 in this case; that result does not establish that contaminated training data is generally safe. section 5.4.1
Figure 5.5 The training data and subsequent data used on an OCSVM detector. This also shows the decision boundary created around the training data and a contour indicating the distance from the decision boundary. Some training points and normal subsequent points fall outside the decision boundary, though only slightly. Most generated outliers are well outside the boundary, though some randomly fall within it.
The plotted boundary shows both kinds of error: some normal points sit just outside it, while some generated outliers land inside. A two-dimensional plot helps explain the detector but does not necessarily carry over to higher-dimensional data. section 5.4
A one-class model can also learn a particular category of known, useful outliers rather than the normal class, helping sort detector results. This differs from training a binary classifier on a few scattered outliers: their locations may give too little guidance for a general boundary. For broad tabular outlier detection, compare OCSVM with other detectors instead of assuming one method will work best. section 15.3.2 section 5.8
