Support vector machine (SVM) is a supervised machine learning algorithm that analyzes and classifies data into one of two categories â€” also known as a binary classifier.
What is Machine Learning?
A computerâ€™s ability to learn from data without explicit programming is called machine learning.Â
It works like this: The machine learns from the existing data and predicts or makes decisions about future data. Your data set must contain known outcomes so that the machine can learn, take the data and adjust it, and apply the machine learning algorithm. The algorithm learns, creates a model, analyzes the model, and then uses that model to make predictions.
There are three main categories of machine learning algorithms:Â
 Supervised learning algorithmsÂ
 Unsupervised learning algorithmsÂ
 Reinforcement learningÂ
Supervised LearningÂ
Supervised learning refers to a data set with known outcomes. If it is unsupervised, there are no known outcomes and you wonâ€™t have the categories or classes necessary for the machine to learn.Â
There are two major types of machine learning algorithms in the supervised learning category:Â
 Classification (which is covered under SVM)Â
 Regression
Classification Algorithms
With classification, you predict categories while in regression, and you generally predict values.Â
In supervised learning, classification is multidimensional in the sense that sometimes you only have two classes (â€śyesâ€ť or â€śnoâ€ť, or, â€śtrueâ€ť or â€śfalseâ€ť). But, sometimes you have more than two. For instance, under risk management or risk modeling, you can have â€ślow riskâ€ť, â€śmedium riskâ€ť, or â€śhigh risk.â€ť SVM is a binary classifier (a classifier used for those true/false, yes/no types of classification problems).
Features are important in supervised learning. If there are several features, SVM may be the better classification algorithm choice as opposed to logistic regression. Under supervised learning, you present the computer with example inputs and their desired outputs (those known outcomes).Â The goal is to learn a general rule that maps inputs to those outputs.Â
Bug detection, customer churn, stock price prediction (not the value of the stock price, but whether or not it will rise or fall), and weather prediction (sunny/not sunny; rain/no rain) are all examples.
Classification algorithms generally take past data (data for which you have known outcomes), train the model, take new data once the model is trained, ingest it, and create predictions (e.g., is it a truck or is it a car?).Â
Learn data analysis, data visualization, machine learning, deep learning, SQL, R, and Python with the Data Science Course with Placement Guarantee. Check out the course now! 
What is SVM?
SVM is a type of classification algorithm that classifies data based on its features. An SVM will classify any new element into one of the two classes.Â
Once you give it some inputs, the algorithm will segregate and classify the data and then create the outputs. When you ingest more new data (an unknown fruit variable in this example), the algorithm will correctly classify the fruit: e.g., â€śappleâ€ť versus â€śorangeâ€ť.Â
Understanding SVMÂ
The following are some examples to understand SVM in detail:
Example 1: Linear SVM classification problem with a 2D data set
The goal of this example is to classify cricket players into batsmen or bowlers using the runstowicket ratio. A player with more runs would be considered a batsman and a player with more wickets would be considered a bowler.Â
If you take a data set of cricket players with runs and wickets in columns next to their names, you could create a twodimensional plot showing a clear separation between bowlers and batsmen. Here we present a data set with clear segregation between bowlers versus batsmen to help understand SVM.
Before separating anything using highlevel mathematics, letâ€™s look at an unknown value, which is new data being introduced into the dataset without a predesignated classification.Â
The next step is to draw a decision boundary, or a line separating the two classes to help classify the new data points.Â
You can actually draw several boundaries, as shown above. Then, you need to find the line of best fit that clearly separates those two groups. The correct line will help you classify the new data point.Â
You can find the best line by computing the maximum margin from equidistant support vectors. Support vectors in this context simply mean the two points â€” one from each class that are closest together, but that maximize the distance between them or the margin.
Â
Note: You may think that the word vector refers to data points. While this may be the case in twodimensional or threedimensional spaces, once you get into higher dimensions with more features in your data set, you need to look at these as vectors. The reason they are support vectors is that the two vectors closest together maximize the distance between the two groups supporting the algorithm.Â
There are a couple of points at the top that are pretty close to one another, and similarly at the bottom of the graph. Shown below are the points that you need to consider. The rest of the points are too far away. The bowler points to the right and the batsman points to the left.Â
Mathematically, you can calculate the distance among all of these points and minimize that distance. Once you pick the support vectors, draw a dividing line, and then measure the distance from each support vector to the line. The best line will always have the greatest margin or distance between the support vectors.
Â
For instance, if you consider the yellow line as a decision boundary, the player with the new data point is the bowler. But, as the margins donâ€™t appear to be maximum, you can come up with a better line.Â
Use other support vectors, draw the decision boundary between those, and then calculate the margin. Notice now that the unknown data point would be considered a batsman.Â
Continue doing this until you find the correct decision boundary with the greatest margin.Â
If you look at the green decision boundary, the line appears to have a maximum margin compared to the other two. This the boundary of greatest margin and when you classify your unknown data value, you can see that it clearly belongs to the batsman's class. The green line divides the data perfectly because it has the maximum margin between the support vectors. At this point, you can be confident with the classification â€” the new data point is indeed a batsman.
Technically, this dividing line is called a hyperplane. In twodimensional spaces, we typically refer to the dividing lines as â€ślines,â€ť but in threedimensional and higher dimensions, they're considered â€śplanesâ€ť or â€ťhyperplanes.â€ť Technically, they are all hyperplanes.Â
The hyperplane with the maximum distance from the support vectors is the one you want. Sometimes called the positive hyperplane (D+), it is the shortest distance to the closest positive point and (D), or the negative hyperplane, which is the shortest distance to the closest negative point.Â
The sum of (D+) and (D) is called the distance margin.Â You should always try to maximize the distance margin to avoid misclassification. For instance, you can see the yellow margin is much smaller than the green margin.Â
This problem set is twodimensional because the classification is only between two classes. It is called a linear SVM.
Example 2: Understanding Kernel SVM. Classification problem with higher dimension data
The data set shown below has no clear linear separation between the two classes. In machine learning parlance, you would say that these are not linearly separable. How can you get the support vector machine to work on such data?Â
Since you can't separate it into two classes using a line, you need to transform it into a higher dimension by employing a kernel function to the data set.Â
A higher dimension enables you to clearly separate the two groups with a plane. Here, you can draw some planes between the green dots and the red dots â€” with the end goal of maximizing the margin.Â
If you let R=the number of dimensions, the kernel function will convert a twodimensional space (R2) to a threedimensional space (R3). Once the data is separated into three dimensions, you can apply SVM and separate the two groups using a twodimensional plane.
This is similar in the higher dimensions (3+D):Â
There are many types of kernel functions, such as:Â
 Gaussian RBF kernel
 Sigmoid kernelÂ
 Polynomial kernelÂ
Depending on the dimensions and how you want to transform the data, you can choose from any of these kernel functions.
Use case: Classifying horses and mules using SVM
Letâ€™s discuss a use case where we use SVM to classify new data as horses or mules.Â
Problem statement: Classify horses and mules using height and weight as the two features. Horses and mules typically have different weights and heights, with horses being heavier and taller.Â
The following are the steps to make the classification:
 Import the data setÂ
 Make sure you have your libraries. The e1071 library has SVM algorithms built in. Create the support vectors using the library.Â
 Once the data is used to train the algorithm plot, the hyperplane gets a visual sense of how the data is separated. If the data is twodimensional or threedimensional, it will be easier to plot.Â
 Use the trained model to classify new values. We should have a training set and a test set. Then, ingest the new data. For our example, weâ€™re going to use the whole dataset to train the algorithm and then see how it performs.Â
 Once you see how it performs, the algorithm will decide whether the image is a horse or a mule.
Here's the R code:Â
Â Â Â Â Â Â Â
RealWorld Applications of SVM
SVM relies on supervised learning algorithms to perform classifications. It is a powerful method to classify unstructured data, make reliable predictions, and reduce redundant information.Â
Whatâ€™s more, SVM has applications in different areas of daily life, such as:Â

Face DetectionÂ
Using image training data, SVM classifies pixels in images like a face or nonface 
Text Classification
Training data is used to categorize different types of documents. For instance, news articles can be classified as â€śbusinessâ€ť or â€śentertainment.â€ťÂ 
Classifying Images
By classifying images with improved techniques, SVM increases search accuracy.Â 
Bioinformatics
SVM algorithms have increased the effectiveness in protein homology detection, cancer classification, gene classification, and more.Â
ConclusionÂ
After that deep dive into SVM, itâ€™s worth backing up to look at the big picture â€“ data science is already widespread in our daily lives, and itâ€™s only going to become more so in the future. Itâ€™s also one of the hottest and most lucrative careers around now. Surely, if you took the time to read this article, you have some interest. Whether youâ€™re a beginner or are looking to move your existing career to the next level, Simplilearnâ€™s expertly designed programs help you with everything you need to know about this promising field. Explore our Machine Learning Certification Course and Data Science with R Certification program to gain all the skills you need to make a great career move. Our Data Science with R Certification program is codeveloped with IBM, and offers you the right blend of highly effective learning approaches â€“ from lifetime access to selfpaced learning, to live online classes, to work on realworld industry projects. Sign up now to boost your career!