SVM Algorithm

Prasad Pokale
5 min readApr 28, 2023

--

What is a Support Vector Machine?

Support Vector Machine or SVM algorithm is a simple yet powerful Supervised Machine Learning Algorithm that can be used for building both regression and classification models. SVM algorithm can perform really well with both linearly separable and non-linearly separable datasets. Even with a limited amount of data, the support vector machine algorithm does not fail to show its magic.

SVM Figure 1: Linearly Separable and Non-linearly Separable Datasets

Before diving right into understanding the SVM algorithm in Machine Learning, let us take a look at the important concepts this blog has to offer.

  • Types of Support Vector Machines
  • Support Vector Machine Algorithms Example
  • Extensions of SVMs
  • Applications of SVMs
  • Conclusion

Types of Support Vector Machines

There are two types of Support Vector Machines:

  1. Linear SVM or Simple SVM: Linear SVM is used for linearly separable data. If a dataset can be classified into two classes with a single straight line, then that data is considered to be linearly separable data, and the classifier is referred to as the linear SVM classifier. It is typically used for linear regression and classification problems.
  2. Nonlinear SVM or Kernel SVM: Nonlinear SVM is used for nonlinearly separated data, i.e., a dataset that cannot be classified by using a straight line. The classifier used in this case is referred to as a nonlinear SVM classifier. It has more flexibility for nonlinear data because more features can be added to fit a hyperplane instead of a two-dimensional space.

Support Vector Machine Algorithm Example

Support vector machine or SVM algorithm is based on the concept of ‘decision planes’, where hyperplanes are used to classify a set of given objects.
Let us start off with a few pictorial examples of support vector machine algorithms. As we can see in Figure 2, we have two sets of data. These datasets can be separated easily with the help of a line, called a decision boundary.

SVM Figure 2: Decision Boundary

But there can be several decision boundaries that can divide the data points without any errors. For example, in Figure 3, all decision boundaries classify the datasets correctly. But how do we pick the best decision boundary?

SVM Figure 3: Other Possible Decision Boundaries

Well, here’s the tip: the best decision boundary is the one that has a maximum distance from the nearest points of these two classes, as shown in Figure 4.

SVM Figure 4: Maximum Distance from the Nearest Points

Also, remember that the nearest points from the optimal decision boundary that maximize the distance are called support vectors.

SVM Figure 5: Margin and Maximum Margin Classifier

The region that the closest points define around the decision boundary is known as the margin.
That is why the decision boundary of a support vector machine model is known as the maximum margin classifier or the maximum margin hyperplane.

In other words, here’s how a support vector machine algorithm model works:

  • First, it finds lines or boundaries that correctly classify the training dataset.
  • Then, from those lines or boundaries, it picks the one that has the maximum distance from the closest data points.

Alright, in the above support vector machine example, the dataset was linearly separable. Now, the question, how do we classify non-linearly separable datasets as shown in Figure 6?

SVM Figure 6: Non-linearly Separable Dataset

Clearly, straight lines can’t be used to classify the above dataset. That is where Kernel SVM comes into the picture.

SVM Figure 7: After Using Kernel Support Vector Classifier

What does Kernel SVM do? How does it find the classifier? Well, the Kernel SVM projects the non-linearly separable datasets of lower dimensions to linearly separable data of higher dimensions. Kernel SVM performs the same in such a way that datasets belonging to different classes are allocated to different dimensions. Interesting, isn’t it?

Extensions of SVMs

SVMs have been extended and modified in several ways to handle different types of problems:

· Multi-class SVM: SVMs were originally designed for binary classification, but several techniques have been developed to extend SVMs to multi-class problems.

· Support vector regression (SVR): SVMs can be adapted for regression problems by using a loss function that measures the distance between the predicted values and the true values.

· One-class SVM: One-class SVM is a variant of SVM that can be used to identify whether a sample belongs to a particular class

· SVM with imbalanced datasets: SVMs can be modified to handle imbalanced datasets by using different strategies, such as adjusting the class weights or oversampling the minority class.

Applications of SVMs

SVMs have been successfully applied to a wide range of problems, including:

· Text classification: SVMs have been used for text classification tasks, such as sentiment analysis, spam detection, and topic classification.

· Image classification: SVMs have been used for image classification tasks, such as object recognition and face detection.

· Bioinformatics: SVMs have been used for bioinformatics tasks, such as gene expression analysis, protein structure prediction, and drug discovery.

· Finance: SVMs have been used for financial applications, such as stock market prediction and credit risk analysis.

Conclusion

In conclusion, SVMs are a powerful and versatile machine learning algorithm that can be used for classification and regression tasks. SVMs have several advantages over other machine learning algorithms, including their ability to handle high-dimensional and nonlinear data, their strong theoretical foundation, and their effectiveness on a wide range of datasets. However, SVMs can also be computationally expensive and require careful selection of the kernel function and hyperparameters. Overall, SVMs are an essential tool in the machine learning toolkit and should be considered for any classification or regression task.

Thanks For Reading😊😊😊

Authors

Sanmit Patil

Amitesh Patil

Pritesh Gaikwad

Prasad Pokale

--

--