0% found this document useful (0 votes)
18 views17 pages

SVM Algorithm: Overview and Examples

SVM_Algorithm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views17 pages

SVM Algorithm: Overview and Examples

SVM_Algorithm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Support Vector Machines (SVM) Algorithm

Support Vector Machine Algorithm


Support Vector Machine or SVM is one of the most popular Supervised Learning
algorithms, which is used for Classification as well as Regression problems.

However, primarily, it is used for Classification problems in Machine Learning.

The goal of the SVM algorithm is to create the best line or decision boundary that
can segregate n-dimensional space into classes so that we can easily put the new
data point in the correct category in the future.

 This best decision boundary is called a hyperplane. SVM chooses the extreme
points/vectors that help in creating the hyperplane.

These extreme cases are called as support vectors, and hence algorithm is
termed as Support Vector Machine.

Consider the below diagram in which there are two different categories that are
classified using a decision boundary or hyperplane:
diagram in which there are two different categories that are
classified using a decision boundary or hyperplane
Function Overloading

Example: SVM can be understood with the example that we have used in
the KNN classifier.

 Suppose we see a strange cat that also has some features of dogs, so if we
want a model that can accurately identify whether it is a cat or dog, so such a
model can be created by using the SVM algorithm.

We will first train our model with lots of images of cats and dogs so that it can
learn about different features of cats and dogs, and then we test it with this
strange creature.

So as support vector creates a decision boundary between these two data
(cat and dog) and choose extreme cases (support vectors),

it will see the extreme case of cat and dog. On the basis of the support
vectors, it will classify it as a cat. Consider the below diagram:
decision boundary between these two data (cat and dog) and choose extreme
cases (support vectors), it will see the extreme case of cat and dog. On the
basis of the support vectors, it will classify it as a cat. Consider the below
diagram:
SVM Applications and its Types
SVM algorithm can be used for Face detection, image classification,
text categorization, etc.

Types of SVM
SVM can be of two types:

Linear SVM: Linear SVM is used for linearly separable data, which
means if a dataset can be classified into two classes by using a single
straight line, then such data is termed as linearly separable data, and
classifier is used called as Linear SVM classifier.

Non-linear SVM: Non-Linear SVM is used for non-linearly separated


data, which means if a dataset cannot be classified by using a straight
line, then such data is termed as non-linear data and classifier used is
called as Non-linear SVM classifier.
Hyperplane and Support Vectors in the SVM algorithm

Hyperplane and Support Vectors in the SVM algorithm:

Hyperplane: There can be multiple lines/decision boundaries to segregate


the classes in n-dimensional space, but we need to find out the best
decision boundary that helps to classify the data points. This best
boundary is known as the hyperplane of SVM.

The dimensions of the hyperplane depend on the features present in the


dataset, which means if there are 2 features (as shown in image), then
hyperplane will be a straight line. And if there are 3 features, then
hyperplane will be a 2-dimension plane.

We always create a hyperplane that has a maximum margin, which means


the maximum distance between the data points.
Support Vectors:

The data points or vectors that are the


closest to the hyperplane and which affect
the position of the hyperplane are termed as
Support Vector. Since these vectors support
the hyperplane, hence called a Support
vector.
How does SVM works?

How does SVM works?


Linear SVM:
The working of the SVM algorithm can be
understood by using an example. Suppose
we have a dataset that has two tags (green
and blue), and the dataset has two features
x1 and x2. We want a classifier that can
classify the pair(x1, x2) of coordinates in
either green or blue. Consider the below
image:
Consider the above image: So as it is 2-d space so by just using a
straight line, we can easily separate these two classes. But there can
be multiple lines that can separate these classes
Consider the below image:
How does SVM works?
Hence, the SVM algorithm helps to find the best line or
decision boundary;
this best boundary or region is called as a hyperplane.
SVM algorithm finds the closest point of the lines from
both the classes.
These points are called support vectors. The distance
between the vectors and the hyperplane is called
as margin.

The goal of SVM is to maximize this margin.

The hyperplane with maximum margin is called


the optimal hyperplane.
Storage Class Comparison
Non-Linear SVM:
Non-Linear SVM:
If data is linearly arranged, then we can separate it by using a
straight line, but for non-linear data, we cannot draw a single
straight line. Consider the below image:
Non-Linear SVM
So to separate these data points, we need to add one more dimension.
For linear data, we have used two dimensions x and y, so for non-linear
data, we will add a third dimension z. It can be calculated as:
z=x2 +y2
By adding the third dimension, the sample space will become as below
image:
Non-Linear SVM
So now, SVM will divide the datasets into classes in the following way.
Consider the below image:
Non-Linear SVM
Since we are in 3-d Space, hence it is looking like a plane
parallel to the x-axis. If we convert it in 2d space with z=1,
then it will become as:

Hence we get a circumference of radius 1 in case of


non-linear data.

Common questions

Powered by AI

Linear SVM is applied to tasks where data can be separated with a straight line. For example, a separation of emails into spam and not spam based on specific linear separable features can be handled by a Linear SVM. Non-Linear SVM, on the other hand, is used when data cannot be separated by a single straight line. An example would be image classification tasks where data features are complex and intertwined, requiring a non-linear decision boundary achieved through kernel functions .

Once an SVM model has been trained, it uses the established hyperplane to classify new data points. For a new instance, the algorithm calculates on which side of the hyperplane the point falls. If it falls on the same side as class A, it is classified as class A; otherwise, it is classified as class B. This decision is influenced by the support vectors which define the optimal hyperplane, ensuring that the classification of new points considers the most critical and closest features of the classes in the training data .

A non-linear SVM is preferred when the dataset cannot be classified with a straight line, meaning the data is not linearly separable. In such cases, to achieve classification, an additional dimension is often introduced to transform the dataset into a higher-dimensional space where it becomes linearly separable. For instance, if the original data is in 2D, a third dimension can be added by mapping inputs through a function such as z = x^2 + y^2, which makes the data linearly separable in this higher-dimensional space .

The hyperplane in Support Vector Machines is a decision boundary used to classify data points in n-dimensional space. The dimensions of the hyperplane depend on the number of features present in the dataset. For example, if there are two features, the hyperplane will be a straight line, while if there are three features, it will be a 2-dimensional plane. Therefore, in an n-dimensional feature space, the hyperplane will be an (n-1)-dimensional subspace .

SVM might not be the best algorithm for very large datasets due to the computational expense of training, especially with non-linear kernels which require significant computational resources. Additionally, SVMs can be less effective with datasets that have significant overlap between classes, as the algorithm's performance heavily relies on clear separability. The effectiveness of SVMs also diminishes with noisy data, such as features that are irrelevant or too numerous relative to the number of samples, leading to overfitting .

The addition of a third dimension, such as z = x^2 + y^2, transforms non-linearly separable data into a higher-dimensional space where it becomes linearly separable. This technique leverages the kernel trick in SVMs, which enables the algorithm to compute the classification boundary without explicitly mapping data to that high-dimensional space. In the transformed space, the separation becomes feasible by drawing a hyperplane, which, when projected back to the original space, results in a non-linear boundary .

Support vectors are the data points that are closest to the hyperplane and have a direct influence on its position and orientation. These points are crucial because they determine the margin of the hyperplane—i.e., the distance between the hyperplane and the nearest data points from either class. The goal of SVM is to maximize this margin, thereby achieving the most distinct separation between the classes. Therefore, support vectors are critical for establishing the optimal hyperplane .

In the context of SVMs, the hyperplane is the decision boundary used to classify data points into different categories based on features. The margin, however, is the distance between this hyperplane and the nearest data points from either class, which are known as support vectors. The key objective in SVM is to find the hyperplane that maximizes this margin, as a larger margin generally leads to better generalization on unseen data .

Support Vector Machines can be applied to both classification and regression tasks. For classification, SVM finds the optimal hyperplane that separates different classes in the feature space. In the case of regression, known as Support Vector Regression (SVR), SVM seeks to fit a model within a threshold that captures the majority of data points. The technique maintains the same principle of using support vectors and maximizing the margin in both scenarios, leading to accurate predictions for classification tasks or ensuring the smallest error margin in regression tasks .

Maximizing the margin between classes in an SVM's hyperplane is necessary because it increases the model's tolerance to errors and improves generalization to new data. A larger margin signifies a more distinct separation between the classes, which tends to lead to better performance and stability of the classifier, reducing the risk of overfitting. It also ensures that the classification is less sensitive to data points near the boundary, thereby enhancing the robustness of the predictions .

You might also like