

{"id":3651,"date":"2017-08-04T12:46:12","date_gmt":"2017-08-04T07:16:12","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=3651"},"modified":"2025-07-28T15:20:55","modified_gmt":"2025-07-28T09:50:55","slug":"svm-support-vector-machine-tutorial","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/","title":{"rendered":"Support Vector Machines Tutorial &#8211; Learn to implement SVM in Python"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2205,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Support-vector_machine&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250822120350\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Support-vector_machine&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 03:13:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-14 12:09:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 09:32:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-26 14:33:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-01 15:56:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-06 16:29:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 12:27:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-19 02:10:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-22 09:47:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-30 06:31:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 16:11:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-11 10:51:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-15 05:18:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-19 05:10:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-25 14:57:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-01 12:52:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-05 10:37:55&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-08 20:22:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 04:07:08&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-16 05:33:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-23 16:40:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 04:13:51&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-06 09:56:40&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-11 20:19:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-15 15:09:19&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 21:23:49&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-23 02:00:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 14:40:20&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-03 06:57:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-09 10:52:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-17 07:37:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-30 14:57:00&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-30 14:57:00&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Support Vector Machines Tutorial &#8211; I am trying to make it a comprehensive plus interactive tutorial, so that you can understand the concepts of SVM easily.<\/p>\n<p>A few days ago, I met a child whose father was buying fruits from a fruitseller. That child wanted to eat strawberry but got confused between the two same looking fruits. After noticing for a while he understands which one is Strawberry and picks one from the basket. Same as that child, support vector machines work. It looks at data and sorts it into one of the two categories.<\/p>\n<p>Still confused? Read the article below to understand SVM in detail with lots of examples.<\/p>\n<h3>Introduction to Support Vector Machines<\/h3>\n<p>SVMs are the most popular algorithm for classification in <a href=\"https:\/\/data-flair.training\/blogs\/types-of-machine-learning-algorithms\/\"><em><strong>machine learning algorithms<\/strong><\/em><\/a>. Their mathematical background is quintessential in building the foundational block for the geometrical distinction between the two classes. We will see how Support vector machines work by observing their implementation in Python and finally, we will look at some of the important applications.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65292\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png\" alt=\"Support Vector Machine Tutorial\" width=\"801\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png 801w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM-150x79.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM-300x157.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM-768x403.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM-520x273.png 520w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/a><\/p>\n<h3>What is SVM?<\/h3>\n<p>Support Vector Machines are a type of supervised machine learning algorithm that provides analysis of data for classification and regression analysis. While they can be used for regression, SVM is mostly used for classification. We carry out plotting in the n-dimensional space. Value of each feature is also the value of the specific coordinate. Then, we find the ideal hyperplane that differentiates between the two classes.<\/p>\n<p>These support vectors are the coordinate representations of individual observation. It is a frontier method for segregating the two classes.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-Frontier-method.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65421\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-Frontier-method.png\" alt=\"SVM Frontier method\" width=\"377\" height=\"320\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-Frontier-method.png 377w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-Frontier-method-150x127.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-Frontier-method-300x255.png 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><\/p>\n<p><em><strong>Don&#8217;t forget to check DataFlair&#8217;s latest tutorial on <a href=\"https:\/\/data-flair.training\/blogs\/clustering-in-machine-learning\/\">Machine Learning Clustering<\/a><\/strong><\/em><\/p>\n<h3>How does SVM work?<\/h3>\n<p>The basic principle behind the working of Support vector machines is simple &#8211; Create a hyperplane that separates the dataset into classes. Let us start with a sample problem. Suppose that for a given dataset, you have to classify red triangles from blue circles. Your goal is to create a line that classifies the data into two classes, creating a distinction between red triangles and blue circles.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/how-does-SVM-work.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65294\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/how-does-SVM-work.png\" alt=\"Working of SVM \" width=\"377\" height=\"264\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/how-does-SVM-work.png 443w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/how-does-SVM-work-150x105.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/how-does-SVM-work-300x211.png 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><\/p>\n<p>While one can hypothesize a clear line that separates the two classes, there can be many lines that can do this job. Therefore, there is not a single line that you can agree on which can perform this task. Let us visualize some of the lines that can differentiate between the two classes as follows &#8211;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-differentiating-two-classes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65297\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-differentiating-two-classes.png\" alt=\"How SVM Works\" width=\"367\" height=\"257\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-differentiating-two-classes.png 443w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-differentiating-two-classes-150x105.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-differentiating-two-classes-300x211.png 300w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/a><\/p>\n<p>In the above visualizations, we have a green line and a red line. Which one do you think would better differentiate the data into two classes? If you choose the red line, then it is the ideal line that partitions the two classes properly. However, we still have not concretized the fact that it is the universal line that would classify our data most efficiently.<\/p>\n<p><em><strong>At this point, you can&#8217;t miss learning about <a href=\"https:\/\/data-flair.training\/blogs\/artificial-neural-network\/\">Artificial Neural Networks<\/a><\/strong><\/em><\/p>\n<p>The green line cannot be the ideal line as it lies too close to the red class. Therefore, it does not provide a proper generalization which is our end goal.<\/p>\n<p>According to SVM, we have to find the points that lie closest to both the classes. These points are known as support vectors. In the next step, we find the proximity between our dividing plane and the support vectors. The distance between the points and the dividing line is known as margin. The aim of an SVM algorithm is to maximize this very margin. When the margin reaches its maximum, the hyperplane becomes the optimal one.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/how-svm-works.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-68882\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/how-svm-works.png\" alt=\"Working of Support vector machine\" width=\"377\" height=\"319\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/how-svm-works.png 377w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/how-svm-works-150x127.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/08\/how-svm-works-300x254.png 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><\/p>\n<p>An SVM\u2019s strength is that it is able to work with linear as well as non-linear data due to the presence of a kernel function. Categorically, these functions including the radial basis function (RBF) or polynomial kernel facilitate the conversion of data to higher dimensions to where a hyperplane is usable in the separation of classes. Because of this, SVM can be utilized in many types of classification problems given that it is very stable.<\/p>\n<p>Also, SVM is more applicable when the input data is high dimensionality which is a property of text categorization and bioinformatics. PCA proves useful in situations where the number of variables is higher than the number of observations. In the case of SCM, the decision boundaries formed by the SVMs do not get over or under-fitted to the data, thereby minimizing the issues related to bias and variance.<\/p>\n<p>The SVM model tries to enlarge the distance between the two classes by creating a well-defined decision boundary. In the above case, our hyperplane divided the data. While our data was in 2 dimensions, the hyperplane was of 1 dimension. For higher dimensions, say, an n-dimensional Euclidean Space, we have an n-1 dimensional subset that divides the space into two disconnected components.<\/p>\n<p><em><strong>Next in this SVM Tutorial, we will see implementing SVM in Python. So, before moving on I recommend revise your <a href=\"https:\/\/data-flair.training\/blogs\/python-tutorials-home\/\">Python Concepts<\/a>.\u00a0<\/strong><\/em><\/p>\n<h3>How to implement SVM in Python?<\/h3>\n<p>In the first step, we will import the important libraries that we will be using in the implementation of SVM in our project.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import pandas as pd\r\nimport numpy as np\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#DataFlair\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.colors import ListedColormap\r\nimport matplotlib.pyplot as plt\r\nfrom sklearn import datasets\r\nfrom sklearn.svm import SVC\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.preprocessing import StandardScaler\r\n\r\n%pylab inline<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65311\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries.jpg\" alt=\"support vector machine - importing libraries\" width=\"583\" height=\"233\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries.jpg 583w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries-150x60.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries-300x120.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/importing-libraries-520x208.jpg 520w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/a><\/p>\n<p>In the second step of implementation of SVM in Python, we will use the iris dataset that is available with the load_iris() method. We will only make use of the petal length and width in this analysis.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pylab.rcParams['figure.figsize'] = (10, 6)\r\n\r\niris_data = datasets.load_iris()\r\n\r\n# We'll use the petal length and width only for this analysis\r\nX = iris_data.data[:, [2, 3]]\r\ny = iris_data.target\r\n\r\n# Input the iris data into the pandas dataframe\r\niris_dataframe = pd.DataFrame(iris_data.data[:, [2, 3]],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0columns=iris_data.feature_names[2:])\r\n\r\n# View the first 5 rows of the data\r\nprint(iris_dataframe.head())\r\n\r\n# Print the unique labels of the dataset\r\nprint('\\n' + 'Unique Labels contained in this data are '\r\n\u00a0\u00a0\u00a0\u00a0\u00a0+ str(np.unique(y)))<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65313 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data.jpg\" alt=\"Importing the data - svm tutorial \" width=\"625\" height=\"290\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data.jpg 625w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data-150x70.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data-300x139.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Importing-the-data-520x241.jpg 520w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68146 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset.jpg\" alt=\"implementing svm in Python \" width=\"545\" height=\"187\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset.jpg 545w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset-150x51.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset-300x103.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/svm-output-using-iris-dataset-520x178.jpg 520w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><\/a><\/p>\n<p><em><strong>ALERT!! You are missing something important &#8211; Don&#8217;t forget to practice the latest machine learning projects. Here is one for you &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/data-science-machine-learning-project-credit-card-fraud-detection\/\">Credit Card Fraud Detection using Machine Learning<\/a>\u00a0<\/strong><\/em><\/p>\n<p>In the next step, we will split our data into training and test set using the train_test_split() function as follows &#8211;<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)\r\n\r\nprint('The training set contains {} samples and the test set contains {} samples'.format(X_train.shape[0], X_test.shape[0]))<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65316 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split.png\" alt=\"Train Test Split in SVM tutorial\" width=\"756\" height=\"153\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split.png 756w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split-150x30.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split-300x61.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Train-Test-Split-520x105.png 520w\" sizes=\"auto, (max-width: 756px) 100vw, 756px\" \/><\/a><\/p>\n<p>Let us now visualize our data. We observe that one of the classes is linearly separable.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">markers = ('x', 's', 'o')\r\ncolors = ('red', 'blue', 'green')\r\ncmap = ListedColormap(colors[:len(np.unique(y_test))])\r\nfor idx, cl in enumerate(np.unique(y)):\r\n    plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1],\r\n           c=cmap(idx), marker=markers[idx], label=cl)<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65320 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data.jpg\" alt=\"Plotting the data - Support vector machines tutorial \" width=\"644\" height=\"108\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data.jpg 644w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data-150x25.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data-300x50.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/Plotting-the-data-520x87.jpg 520w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65307 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data.png\" alt=\"visualizing the data in SVM\" width=\"598\" height=\"361\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data.png 598w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data-150x91.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data-300x181.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/visualizing-the-data-520x314.png 520w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p>Then, we will perform scaling on our data. Scaling will ensure that all of our data-values lie on a common range such that there are no extreme values.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">standard_scaler = StandardScaler()\r\n#DataFlair\r\nstandard_scaler.fit(X_train)\r\n\r\nX_train_standard = standard_scaler.transform(X_train)\r\nX_test_standard = standard_scaler.transform(X_test)\r\n\r\nprint('The first five rows after standardisation look like this:\\n')\r\nprint(pd.DataFrame(X_train_standard, columns=iris_dataframe.columns).head())<\/pre>\n<p><strong>Output Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65308 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM.jpg\" alt=\"scaling data in Support vector machines\" width=\"705\" height=\"311\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM.jpg 705w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM-150x66.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM-300x132.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/scaling-data-in-SVM-520x229.jpg 520w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/a><\/p>\n<p>After we have pre-processed our data, the next step is the implementation of the SVM model as follows. We will make use of the SVC function provided to us by the sklearn library. In this instance, we will select our kernel as \u2018rbf\u2019.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#DataFlair\r\nSVM = SVC(kernel='rbf', random_state=0, gamma=.10, C=1.0)\r\nSVM.fit(X_train_standard, y_train)\r\n\r\nprint('Accuracy of our SVM model on the training data is {:.2f} out of 1'.format(SVM.score(X_train_standard, y_train)))\r\n\r\nprint('Accuracy of our SVM model on the test data is {:.2f} out of 1'.format(SVM.score(X_test_standard, y_test)))<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65323 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model.png\" alt=\"implementation of SVM model\" width=\"696\" height=\"156\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model.png 696w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model-150x34.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model-300x67.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/implementation-of-SVM-model-520x117.png 520w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/a><\/p>\n<p><em><strong>DataFlair&#8217;s Recommendation &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-data-science-project-customer-segmentation\/\">Customer Segmentation using R and Machine Learning<\/a><\/strong><\/em><\/p>\n<p>After we have achieved our accuracy, the best course of action would be to visualize our SVM model. We can do this by creating a function called decision_plot() and passing values to it as follows &#8211;<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import warnings\r\n\r\ndef versiontuple(version):\r\n   return tuple(map(int, (version.split(\".\"))))\r\n\r\ndef decision_plot(X, y, classifier, test_idx=None, resolution=0.02):\r\n\r\n   # setup marker generator and color map\r\n   markers = ('s', 'x', 'o', '^', 'v')\r\n   colors = ('red', 'blue', 'green', 'gray', 'cyan')\r\n   cmap = ListedColormap(colors[:len(np.unique(y))])\r\n\r\n   # plot the decision surface\r\n   x1min, x1max = X[:, 0].min() - 1, X[:, 0].max() + 1\r\n   x2min, x2max = X[:, 1].min() - 1, X[:, 1].max() + 1\r\n   xx1, xx2 = np.meshgrid(np.arange(x1min, x1max, resolution),\r\n                 np.arange(x2min, x2max, resolution))\r\n   Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)\r\n   Z = Z.reshape(xx1.shape)\r\n   plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)\r\n   plt.xlim(xx1.min(), xx1.max())\r\n   plt.ylim(xx2.min(), xx2.max())\r\n\r\n   for idx, cl in enumerate(np.unique(y)):\r\n      plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1],\r\n              alpha=0.8, c=cmap(idx),\r\n              marker=markers[idx], label=cl)\r\n<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65324 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM.jpg\" alt=\"decision plot function in Support vector machine\" width=\"726\" height=\"454\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM.jpg 726w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM-150x94.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM-300x188.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-function-in-SVM-520x325.jpg 520w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">decision_plot(X_test_standard, y_test, SVM)<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-call.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65325\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-call.jpg\" alt=\"decision plot call\" width=\"495\" height=\"56\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-call.jpg 495w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-call-150x17.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/decision-plot-call-300x34.jpg 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65305\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot.png\" alt=\"SVM - decision plot\" width=\"597\" height=\"361\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot.png 597w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot-150x91.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot-300x181.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/SVM-decision-plot-520x314.png 520w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/a><\/p>\n<p><em><strong><a href=\"https:\/\/data-flair.training\/blogs\/convolutional-neural-networks\/\">Convolutional Neural Network<\/a> &#8211; You must learn this concept for becoming an expert<\/strong><\/em><\/p>\n<h3>Advantages and Disadvantages of Support Vector Machine<\/h3>\n<h4>Advantages of SVM<\/h4>\n<ul>\n<li>Guaranteed Optimality: Owing to the nature of Convex Optimization, the solution will always be global minimum not a local minimum.<\/li>\n<li>Abundance of Implementations: We can access it conveniently, be it from Python or Matlab.<\/li>\n<li>SVM can be used for linearly separable as well as non-linearly separable data. Linearly separable data is the hard margin whereas non-linearly separable data poses a soft margin.<\/li>\n<li>SVMs provide compliance to the semi-supervised learning models. It can be used in areas where the data is labeled as well as unlabeled. It only requires a condition to the minimization problem which is known as the Transductive SVM.<\/li>\n<li>Feature Mapping used to be quite a load on the computational complexity of the overall training performance of the model. However, with the help of Kernel Trick, SVM can carry out the feature mapping using simple dot product.<\/li>\n<\/ul>\n<h4>Disadvantages of SVM<\/h4>\n<ul>\n<li>SVM is incapable of handling text structures. This leads to loss of sequential information and thereby, leading to worse performance.<\/li>\n<li>Vanilla SVM cannot return the probabilistic confidence value that is similar to logistic regression. This does not provide much explanation as confidence of prediction is important in several applications.<\/li>\n<li>Choice of the kernel is perhaps the biggest limitation of the support vector machine. Considering so many kernels present, it becomes difficult to choose the right one for the data.<\/li>\n<\/ul>\n<p><em><strong>Learn everything about <a href=\"https:\/\/data-flair.training\/blogs\/recurrent-neural-networks\/\">Recurrent Neural Networks and its applications<\/a><\/strong><\/em><\/p>\n<h3>How to Tune SVM Parameters?<\/h3>\n<h4>Kernel<\/h4>\n<p>Kernel in the SVM is responsible for transforming the input data into the required format. Some of the kernels used in SVM are linear, polynomial and radial basis function (RBF). For creating a non-linear hyperplane, we use RBF and Polynomial function. For complex applications, one should use more advanced kernels to separate classes that are nonlinear in nature. With this transformation, one can obtain accurate classifiers.<\/p>\n<h4>Regularization<\/h4>\n<p>We can maintain regularization by adjusting it in the Scikit-learn\u2019s C parameters. C denotes a penalty parameter representing an error or any form of misclassification. With this misclassification, one can understand how much of the error is actually bearable. Through this, you can nullify the compensation between the misclassified term and the decision boundary. With a smaller C value, we obtain hyperplane of small margin and with a larger C value, we obtain hyperplane of larger value.<\/p>\n<h4>Gamma<\/h4>\n<p>With a lower value of Gamma will create a loose fit of the training dataset. On the contrary, a high value of gamma will allow the model to get fit more appropriately. A low value of gamma only provides consideration to the nearby points for the calculation of a separate plane whereas the high value of gamma will consider all the data-points to calculate the final separation line.<\/p>\n<h3>Applications of SVM<\/h3>\n<p>Some of the areas where Support Vector Machines are used are as follows &#8211;<\/p>\n<ul>\n<li>\n<h4>Face Detection<\/h4>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Support-vector_machine\">SVMs<\/a> are capable of classifying images of persons in an environment by creating a square box that separates the face from the rest.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-64552\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks.jpg\" alt=\"Neural Networks Applications - Image Recognition\" width=\"197\" height=\"185\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks.jpg 532w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks-150x141.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks-300x282.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/image-recognition-in-neural-networks-520x489.jpg 520w\" sizes=\"auto, (max-width: 197px) 100vw, 197px\" \/><\/a><\/p>\n<ul>\n<li>\n<h4>Text and hypertext categorization<\/h4>\n<\/li>\n<\/ul>\n<p>SVMs can be used for document classification in the sense that it performs the text and hypertext categorization. Based on the score generated, it performs a comparison with the threshold value.<\/p>\n<ul>\n<li>\n<h4>Bioinformatics<\/h4>\n<\/li>\n<\/ul>\n<p>In the field of bioinformatics, SVMs are used for protein and genomic classification. They can classify the genetic structure of the patients based on their biological problems.<\/p>\n<ul>\n<li>\n<h4>Handwriting recognition<\/h4>\n<\/li>\n<\/ul>\n<p>Another area where support vector machines are used for visual recognition is handwriting recognition.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/handwritten-character-recognition-Anns-applications.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-64555\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/handwritten-character-recognition-Anns-applications.png\" alt=\"Artificial Neural Networks applications - Character Recognition\" width=\"320\" height=\"128\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/handwritten-character-recognition-Anns-applications.png 500w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/handwritten-character-recognition-Anns-applications-150x60.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/handwritten-character-recognition-Anns-applications-300x120.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>In this article, we studied about Support Vector Machines. Support Vector Machine (SVM) is a powerful machine learning algorithm used for classification and regression. It works by drawing a line or curve that best separates the data into different classes. This line is called a hyperplane.<\/p>\n<p>The idea is to find the line that not only separates the classes but also stays as far away from them as possible. The data points closest to the hyperplane are called support vectors, and they help define the best decision boundary.<\/p>\n<p>What do you want to learn next? Comment below. DataFlair will surely help you.<\/p>\n<p><em><strong>Till then keep exploring the <a href=\"https:\/\/data-flair.training\/blogs\/machine-learning-tutorials-home\/\">Machine Learning Tutorials<\/a>. Happy learning<\/strong><\/em>\ud83d\ude0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Support Vector Machines Tutorial &#8211; I am trying to make it a comprehensive plus interactive tutorial, so that you can understand the concepts of SVM easily. A few days ago, I met a child&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":65292,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[13984,14001,20981,20983,14009,20982],"class_list":["post-3651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-support-vector-machine","tag-svm-algorithm","tag-svm-applications","tag-svm-in-python","tag-svm-tutorial","tag-what-is-svm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Support Vector Machines Tutorial - Learn to implement SVM in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Support Vector Machines looks at data &amp; sorts it into one of the two categories. Learn what is SVM &amp; its working with examples\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Support Vector Machines Tutorial - Learn to implement SVM in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Support Vector Machines looks at data &amp; sorts it into one of the two categories. Learn what is SVM &amp; its working with examples\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-04T07:16:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-28T09:50:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"801\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Support Vector Machines Tutorial - Learn to implement SVM in Python - DataFlair","description":"Support Vector Machines looks at data & sorts it into one of the two categories. Learn what is SVM & its working with examples","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Support Vector Machines Tutorial - Learn to implement SVM in Python - DataFlair","og_description":"Support Vector Machines looks at data & sorts it into one of the two categories. Learn what is SVM & its working with examples","og_url":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-08-04T07:16:12+00:00","article_modified_time":"2025-07-28T09:50:55+00:00","og_image":[{"width":801,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png","type":"image\/png"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Support Vector Machines Tutorial &#8211; Learn to implement SVM in Python","datePublished":"2017-08-04T07:16:12+00:00","dateModified":"2025-07-28T09:50:55+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/"},"wordCount":1800,"commentCount":10,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png","keywords":["Support Vector Machine","SVM Algorithm","SVM Applications","SVM in python","SVM Tutorial","what is SVM"],"articleSection":["Machine Learning Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/","url":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/","name":"Support Vector Machines Tutorial - Learn to implement SVM in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png","datePublished":"2017-08-04T07:16:12+00:00","dateModified":"2025-07-28T09:50:55+00:00","description":"Support Vector Machines looks at data & sorts it into one of the two categories. Learn what is SVM & its working with examples","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/introduction-to-SVM.png","width":801,"height":420,"caption":"Support Vector Machine Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/svm-support-vector-machine-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Machine Learning Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/machine-learning\/"},{"@type":"ListItem","position":3,"name":"Support Vector Machines Tutorial &#8211; Learn to implement SVM in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/3651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=3651"}],"version-history":[{"count":10,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/3651\/revisions"}],"predecessor-version":[{"id":146262,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/3651\/revisions\/146262"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/65292"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=3651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=3651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=3651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}