Support Vector Machines
Support Vector Machines
Dr Sridhar R
Dept. of ISE, GAT
Support Vector Machines
Support Vector Machine (SVM) is a supervised machine learning algorithm that
can be used for both classification or regression challenges. However, it is
mostly used in classification problems.
In the SVM algorithm, we plot each data item as a point in
n-dimensional space (where n is a number of features you have) with the value of
each feature being the value of a particular coordinate. Then, we perform
classification by finding the hyper-plane that differentiates the two classes very
well.
Support Vector Machines
Support Vectors are simply the coordinates of individual observation. The SVM classifier is a
frontier that best segregates the two classes (hyper-plane/ line).
Example
Support Vector Machines
Support Vector Machines
Support Vector Machines
Support Vector Machines
Support Vector Machines - separable
case Support Vector Machines -
non-separable case
Linearly Separable Case
Dataset is linearly separable and the classification problem is Binary
classification or two class classification.
Any of these
would be fine..
..but which is
best?
Examples of Bad Decision Boundaries
Class 2 Class 2
Class 1 Class 1
Mehryar Mohri - Foundations of Machine Learning page 13
Linearly Separable Case
Define the hyperplanes H such that:
w•xi+b ≥ +1 when yi =+1 H1
w•xi+b ≤ -1 when yi = –1 H0
H2
H1 and H2 are the margins: d
+
H1: w•xi+b = +1 d
-
H
H2: w•xi+b = –1
The points on the margins H1 and
H2 are the tips of the Support
Vectors.The plane H0 is the median
in between, where w•xi+b =0 d+ = the shortest distance to the closest positive point
d- = the shortest distance to the closest negative point
In order to maximize the margin, we need to minimize ||w||. With the condition that there are no
datapoints between H1 and H2:
cancer_data = datasets.load_breast_cancer()
print(cancer_data.data[5])
Output:
Output:
(569, 30) [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1
0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0
1 0 0 1 0 0 1 1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