# Understanding SVM, its Type, Applications and How to use with Python

Blog Contents:

- Introduction to SVM
- What is SVM?
- Types of SVM
- Application of SVM
- How to SVM in Machine learning model using Python

**Introduction to SVM :**

SVM (Support Vector Machine) is a powerful machine learning tool that is used for classification and regression.

**What is SVM?**

It is a supervised Machine learning algorithm that is used for classification and regression you can even detect outliers with it. It is very for classification problems when your data is complex -small and medium-sized. The purpose of SVM is to draw lines or decision boundaries that can separate n-dimensional space this is very useful for classification. The best plane or decision boundary which separate the data most accurately is called Hyperplane.

**Type of SVM:**

There are two types of SVM

- Linear SVM: Those SVM models in which data can be classified using a straight line are called Linear SVM.
Image 1 - Non-Linear SVM: Those SVM models in which data can be classified using a Non-Linear line are called Non-Linear SVM.

Image 2 |

Application of SVM:

There are many applications of SVM model like:

- Classification of Images
- Face detection
- Bioinformatics
- Handwriting Recognition and much more

My Github For Other Project : Link [I am looking for a fresher Internship or entry-level machine learning/data science job I have learned machine learning myself,I am a mechanical engineer currently doing freelance work in 3D animation. if anybody can help me please comment I will be thankful.CONSTRUCTIVE CRITICISM HIGHLY APPRECIATE]

Python Code With SVM

import numpy as np

import matplotlib.pyplot as plt

from sklearn import svm, datasets

from ipywidgets import interactive

# import some data to play with

iris = datasets.load_iris()

X = iris.data[:, :2] # we only take the first two features. We could

# avoid this ugly slicing by using a two-dim dataset

y = iris.target

h = .02 # step size in the mesh

# we create an instance of SVM and fit out data. We do not scale our

# data since we want to plot the support vectors

def f(C):

# SVM regularization parameter

svc = svm.SVC(kernel='linear', C=C).fit(X, y)

rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X, y)

poly_svc = svm.SVC(kernel='poly', degree=3, C=C).fit(X, y)

lin_svc = svm.LinearSVC(C=C).fit(X, y)

# create a mesh to plot in

x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1

y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1

xx, yy = np.meshgrid(np.arange(x_min, x_max, h),

np.arange(y_min, y_max, h))

# title for the plots

titles = ['SVC with linear kernel',

'LinearSVC (linear kernel)',

'SVC with RBF kernel',

'SVC with polynomial (degree 3) kernel']

for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):

# Plot the decision boundary. For that, we will assign a color to each

# point in the mesh [x_min, x_max]x[y_min, y_max].

plt.subplot(2, 2, i + 1)

plt.subplots_adjust(wspace=0.4, hspace=0.4)

Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot

Z = Z.reshape(xx.shape)

plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)

# Plot also the training points

plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)

plt.xlabel('Sepal length')

plt.ylabel('Sepal width')

plt.xlim(xx.min(), xx.max())

plt.ylim(yy.min(), yy.max())

plt.xticks(())

plt.yticks(())

plt.title(titles[i])

plt.show()

interactive_plot = interactive(f,C = (1,100))

interactive_plot

Other Blog You might also like:

## 0 Comments

if you are not getting it then ask i am glad to help