One-Class SVM for Novelty Detection
What you'll learn: How to use One-Class SVM to draw a boundary around normal data so anything outside is flagged as an anomaly.
The Core Idea
Imagine you're a security guard who's seen thousands of regular employees enter a building, but you've never seen an intruder. How do you recognize one? You learn what "normal" looks like so well that anything different stands out.
One-Class SVM does exactly this for data. Unlike regular SVMs that learn to separate two classes, One-Class SVM learns the boundary of one class—your normal data. It creates a decision boundary that wraps around the typical data points in feature space. Anything that falls outside this boundary is considered novel or anomalous.
How It Works
One-Class SVM maps your data into a high-dimensional space (often using the RBF kernel you learned earlier) and finds the smallest hypersphere or hyperplane that encloses most of your normal training data. It allows a small fraction of points to be outliers (controlled by a parameter nu), making it robust to minor noise in your training set.
Think of it as drawing a fence around a flock of sheep. The fence is tight enough to keep the group together but allows for some natural wandering. Any creature outside the fence is likely not a sheep.
Key Parameters
nu: Controls the fraction of training data allowed outside the boundary (typically 0.01 to 0.1)kernel: Usually RBF, determines how the boundary curvesgamma: Controls boundary smoothness (smaller = smoother)
Key Takeaway: One-Class SVM learns what "normal" looks like by fitting a tight boundary around your training data, making it excellent for novelty detection when you only have examples of normal behavior.