{"id":134313,"date":"2026-08-26T12:02:03","date_gmt":"2026-08-26T06:32:03","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=134313"},"modified":"2026-08-26T12:02:06","modified_gmt":"2026-08-26T06:32:06","slug":"what-is-one-class-svm","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/what-is-one-class-svm\/","title":{"rendered":"What is One-Class SVM: A Complete Guide for Beginners"},"content":{"rendered":"\n<p>Most machine learning classification problems assume you have labeled examples of every class you want to detect. But what if you only have examples of normal behavior and want to detect anything unusual? This is the anomaly detection problem, and it comes up constantly in the real world. Fraud looks different every time it happens. Network attacks take new forms that have never been seen before. Manufacturing defects vary in unexpected ways. One-Class SVM was designed for exactly these situations, learning what normal looks like and raising an alarm when something does not fit.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR Summary<\/strong><\/h2>\n\n\n\n<ol>\n<li>One-Class SVM is a machine learning algorithm used for anomaly detection and novelty detection, trained on only one class of data, the normal class<\/li>\n\n\n\n<li>Unlike regular classification which learns to distinguish between two or more classes, One-Class SVM learns the boundary around normal data and flags anything outside that boundary as an anomaly<\/li>\n\n\n\n<li>It works by finding a hyperplane that separates normal data points from the origin in a high-dimensional feature space with maximum margin<\/li>\n\n\n\n<li>Key applications include fraud detection, network intrusion detection, medical diagnosis, and manufacturing quality control<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Is a Support Vector Machine?<\/strong><\/h2>\n\n\n\n<p>A standard <a href=\"https:\/\/www.guvi.in\/blog\/what-is-svm-in-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\">SVM <\/a>is a binary classification algorithm. Given labeled data from two classes, it finds the hyperplane that best separates them, maximizing the margin between the two classes. The data points closest to the boundary are called support vectors and they define where the boundary sits.<\/p>\n\n\n\n<p>In two dimensions, a hyperplane is just a line. In three dimensions it is a plane. In higher dimensions it is still called a hyperplane but the intuition is the same: a flat boundary that divides the feature space into two regions.<\/p>\n\n\n\n<p>SVMs are powerful because they use a technique called the kernel trick to handle data that is not linearly separable. The <a href=\"https:\/\/www.guvi.in\/blog\/non-linear-svm-in-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\">kernel function <\/a>transforms data into a higher-dimensional space where a linear boundary becomes possible, then maps the boundary back to the original space where it may look curved or complex.<\/p>\n\n\n\n<p><strong>Read More: <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/supervised-and-unsupervised-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Supervised and Unsupervised Learning<\/strong><\/a><\/p>\n\n\n\n<p>Want to build practical machine learning skills covering anomaly detection, supervised and unsupervised learning, and real-world model deployment? Explore <strong>HCL GUVI&#8217;s <\/strong><a href=\"https:\/\/www.guvi.in\/mlp\/artificial-intelligence-and-machine-learning?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=one-class-svm-explained\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Artificial Intelligence &amp; Machine Learning Course<\/strong><\/a>, designed to help you go from ML fundamentals to production-ready models.<a href=\"https:\/\/www.guvi.in\/courses\/?utm_source=blog&amp;utm_medium=content&amp;utm_campaign=one-class-svm\">&nbsp;<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Makes One-Class SVM Different<\/strong><\/h2>\n\n\n\n<p>A regular SVM needs labeled data from two classes. One-Class SVM removes this requirement. It trains using only normal data and learns a boundary around that data. At prediction time, any new point that falls inside the boundary is labeled normal and any point outside is labeled an anomaly.<\/p>\n\n\n\n<p>The intuition is straightforward. Imagine all your normal training data forms a cluster in feature space. One-Class SVM draws the tightest possible boundary around that cluster. When a new data point arrives, the algorithm simply checks whether it is inside or outside the boundary. Inside means normal. Outside means something unusual has happened.<\/p>\n\n\n\n<p>This is different from regular classification in a fundamental way. The algorithm has never seen an anomaly during training. It has no idea what an anomaly looks like. It only knows what normal looks like and uses that knowledge to define what is not normal.<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\"> \n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong> \n  <br \/><br \/> \n   One-Class SVM using an RBF kernel is mathematically equivalent to a density estimation technique called Parzen window estimation in the limit, meaning it implicitly learns the probability density of your normal data even though it was not explicitly designed as a density estimator.\u00a0\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How One-Class SVM Works Mathematically<\/strong><\/h2>\n\n\n\n<p>You do not need to memorize the math to use One-Class SVM effectively, but understanding the core idea helps you tune it better.<\/p>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/One-class_classification\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">One-Class SVM<\/a> works by mapping all training data into a high-dimensional feature space using a kernel function. In that high-dimensional space it tries to find a hyperplane that separates all the normal training data from the origin, the zero point of that space, with as large a margin as possible.<\/p>\n\n\n\n<p>The origin acts as a reference point representing the absence of any data. By pushing normal data as far as possible from the origin, the algorithm creates a region in feature space that belongs to the normal class. Data points that map close to or on the wrong side of the origin are treated as anomalies.<\/p>\n\n\n\n<p>The parameter nu controls the trade-off between how tight the boundary is and how many training points are allowed to fall outside it. A lower nu creates a tighter boundary with fewer training points treated as anomalies. A higher nu allows a looser boundary that accepts more variation in what counts as normal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Two Key Parameters You Need to Understand<\/strong><\/h2>\n\n\n\n<ol>\n<li><strong>Nu<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Nu is the most important parameter in One-Class SVM. It has a specific mathematical meaning: it is an upper bound on the fraction of training examples that can be treated as outliers and a lower bound on the fraction of support vectors.<\/p>\n\n\n\n<p>In practice, if you set nu to 0.05, the algorithm allows up to 5 percent of your training data to be treated as outliers when fitting the boundary. Setting nu too low makes the boundary very tight and causes the model to flag too many normal points as anomalies in production. Setting nu too high makes the boundary too loose and causes the model to miss real anomalies.<\/p>\n\n\n\n<p>A good starting point is to set nu to your estimate of the true anomaly rate in your data. If you expect roughly 2 percent of transactions to be fraudulent, start with nu around 0.02.<\/p>\n\n\n\n<ol start=\"2\">\n<li><strong>Kernel and Gamma<\/strong><\/li>\n<\/ol>\n\n\n\n<p>The kernel function controls the shape of the decision boundary. The most common choices are:<\/p>\n\n\n\n<p>The RBF (Radial Basis Function) kernel is the default and works well for most problems. It creates smooth, curved boundaries that adapt to the shape of your normal data. The gamma parameter controls how tightly the boundary wraps around training points. High gamma creates a very tight boundary that follows individual training points closely, risking overfitting. Low gamma creates a smoother, more generalized boundary.<\/p>\n\n\n\n<p>The linear kernel creates a flat boundary and works best when your normal data is roughly linearly separable from anomalies in the original feature space. Use it when you have very high-dimensional data like text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>One-Class SVM vs Other Anomaly Detection Methods<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Method<\/strong><\/td><td><strong>Best For<\/strong><\/td><td><strong>Key Limitation<\/strong><\/td><\/tr><tr><td>One-Class SVM<\/td><td>High-dimensional data, <a href=\"https:\/\/www.guvi.in\/blog\/non-linear-svm-in-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\">non-linear<\/a> boundaries<\/td><td>Slow on very large datasets<\/td><\/tr><tr><td>Isolation Forest<\/td><td>Large datasets, fast training<\/td><td>Less effective on high-dimensional data<\/td><\/tr><tr><td>Local Outlier Factor<\/td><td>Density-based anomalies, small datasets<\/td><td>Does not generalize to new data easily<\/td><\/tr><tr><td>Autoencoder<\/td><td>Complex patterns, image and sequence data<\/td><td>Requires more data and tuning<\/td><\/tr><tr><td>Statistical methods (Z-score)<\/td><td>Simple univariate anomalies<\/td><td>Assumes normal distribution<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>One-Class SVM is the strongest choice when your data is high-dimensional, you expect non-linear boundaries between normal and anomalous regions, and your dataset is small to medium in size. For very large datasets with millions of rows, Isolation Forest is faster and often equally accurate.<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\"> \n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong> \n  <br \/><br \/> \n   One-Class SVM was first introduced by Bernhard Sch\u00f6lkopf and colleagues in a paper published in 2001, extending the original SVM framework developed by Vapnik in the 1990s. ecting examples of every possible anomaly type is either impossible or impractical.\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Implementing One-Class SVM in Python<\/strong><\/h2>\n\n\n\n<p>Scikit-learn provides a clean, ready-to-use implementation of One-Class SVM through its OneClassSVM class.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.svm import OneClassSVM\n\nfrom sklearn.preprocessing import StandardScaler\n\nimport numpy as np\n\nscaler = StandardScaler()\n\nX_train_scaled = scaler.fit_transform(X_train)\n\nX_test_scaled = scaler.transform(X_test)\n\nmodel = OneClassSVM(kernel=\"rbf\", nu=0.05, gamma=\"scale\")\n\nmodel.fit(X_train_scaled)\n\npredictions = model.predict(X_test_scaled)<\/code><\/pre>\n\n\n\n<p>The predict method returns 1 for normal points and -1 for anomalies. Always scale your features before fitting One-Class SVM because it is sensitive to feature magnitude. StandardScaler centers each feature to zero mean and unit variance, which ensures no single feature dominates the boundary purely because of its scale.<\/p>\n\n\n\n<p>You can also get a continuous anomaly score for each point using decision_function, which returns a negative value for anomalies and a positive value for normal points. The more negative the score, the more anomalous the point.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scores = model.decision_function(X_test_scaled)<\/code><\/pre>\n\n\n\n<p>Using scores rather than binary predictions gives you more flexibility to set thresholds based on your specific precision and recall requirements.<\/p>\n\n\n\n<p>Want to build practical machine learning skills covering anomaly detection, supervised and unsupervised learning, and real-world model deployment? Explore <strong>HCL GUVI&#8217;s <\/strong><a href=\"https:\/\/www.guvi.in\/mlp\/artificial-intelligence-and-machine-learning?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=one-class-svm-explained\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Artificial Intelligence &amp; Machine Learning Course<\/strong><\/a>, designed to help you go from ML fundamentals to production-ready models.<a href=\"https:\/\/www.guvi.in\/courses\/?utm_source=blog&amp;utm_medium=content&amp;utm_campaign=one-class-svm\">&nbsp;<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>One-Class SVM fills an important gap in the machine learning toolkit: anomaly detection when you have abundant normal data but few or no labeled anomalies to train on.&nbsp;<\/p>\n\n\n\n<p>Its ability to learn complex, non-linear boundaries around normal data using kernel functions makes it particularly effective for high-dimensional problems like fraud detection, network security, and medical screening.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQ<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1787214977471\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What is One-Class SVM used for?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>One-Class SVM is used for anomaly detection and novelty detection, identifying data points that differ significantly from a training set of normal examples without requiring labeled anomaly examples during training.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1787214982026\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>How is One-Class SVM different from a regular SVM?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A regular SVM learns a boundary between two labeled classes. One-Class SVM trains on only one class and learns a boundary around normal data, flagging anything outside as an anomaly.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1787214989849\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What does the nu parameter control in One-Class SVM?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Nu is an upper bound on the fraction of training points that can be treated as outliers. Set it close to your expected anomaly rate in the data for best results.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1787215001747\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Which kernel should I use for One-Class SVM?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Start with the RBF kernel, which is the default and works well for most problems. Use the linear kernel for very high-dimensional data like text features.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1787215011902\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>When should I use Isolation Forest instead of One-Class SVM?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use Isolation Forest when your dataset has more than a few hundred thousand rows. It trains much faster than One-Class SVM at large scale with comparable accuracy on most anomaly detection tasks.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1787215020122\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>How do I evaluate a One-Class SVM model?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use precision, recall, and F1 score on a test set that includes both normal points and known anomalies. Accuracy alone is misleading for anomaly detection because anomalies are rare and a model that predicts everything as normal achieves high accuracy while detecting nothing.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Most machine learning classification problems assume you have labeled examples of every class you want to detect. But what if you only have examples of normal behavior and want to detect anything unusual? This is the anomaly detection problem, and it comes up constantly in the real world. Fraud looks different every time it happens. [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":134322,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[933],"tags":[],"views":"21","authorinfo":{"name":"HCL GUVI","url":"https:\/\/www.guvi.in\/blog\/author\/guvipr\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/08\/One-Class-SVM-Explained-1-300x116.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/134313"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=134313"}],"version-history":[{"count":7,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/134313\/revisions"}],"predecessor-version":[{"id":135655,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/134313\/revisions\/135655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/134322"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=134313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=134313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=134313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}