Module 3 KNN and SVM
Module 3 KNN and SVM
K-NEAREST
NEIGHBOR
Reference link:
https://www.youtube.com/watch?v=HVXime0nQeI
Simple ASET
• Analogy..
Tell me about your friends(who your neighbors
are) and I will tell you who you are.
Instance-based ASET
Learning
• K-Nearest Neighbors
• Memory-Based Reasoning
• Example-Based Reasoning
• Instance-Based Learning
• Lazy Learning
What is KNN? ASET
Compute
Distance
Test
Record
Training
Records Choose k of the
“nearest” records
Distance Between Neighbors ASET
n
D( X ,Y ) (x2
i
i1
yi )
K-Nearest Neighbor Algorithm ASET
11
Compute Euclidean Distance ASET
12
Use k=5 ASET
13
How to Select K? ASET
X X X
Weaknesses of KNN
https://www.youtube.com/watch?v=efR1C6CvhmE
18
Support Vector Machine ASET
How can you separate the given data points
in the search space?
20
Support Vector Machine ASET
21
Support Vector Machine ASET
22
Support Vector Machine ASET
Hyperplane(Decision surface ):
•The hyperplane is a function which is used to differentiate between features.
In 2-D, the function used to classify between features is a line whereas, the
function used to classify the features in a 3-D is called as a plane similarly the
function which classifies the point in higher dimension is called as a
hyperplane.
•Let’s say there are “m” dimensions:
•Thus the equation of the hyperplane in the ‘M’ dimension can be given as-
where,
Wi = vectors(W0,W1,W2,W3……Wm)
b = biased term (W0)
X = variables.
23
Support Vector Machine ASET
24
Support Vector Machine ASET
• For the point X1 :
• Explanation: when the point X1 we can say that point lies on the hyperplane and the
equation determines that the product of our actual output and the hyperplane
equation is 1 which means the point is correctly classified in the positive domain.
• Explanation: when the point X3 we can say that point lies away from the hyperplane
and the equation determines that the product of our actual output and the hyperplane
equation is greater 1 which means the point is correctly classified in the positive
domain.
25
Support Vector Machine ASET
• for the point X4:
• Explanation: when the point X4 we can say that point lies on the hyperplane in the
negative region and the equation determines that the product of our actual output and the
hyperplane equation is equal to 1 which means the point is correctly classified in the
negative domain.
• for the point X6 :
• Explanation: when the point X6 we can say that point lies away from the hyperplane in
the negative region and the equation determines that the product of our actual output and
the hyperplane equation is greater 1 which means the point is correctly classified in the
negative domain.
26
Support Vector Machine ASET
Explanation: When Xi = 7 the point is classified incorrectly because for point 7 the
wT + b will be smaller than one and this violates the constraints. So we found the
misclassification because of constraint violation. Similarly, we can also say for points
Xi = 8.
27
Support Vector Machine ASET
So we can see that if the points are linearly separable then only our hyperplane is able to
distinguish between them and if any outlier is introduced then it is not able to separate them.
So these type of SVM is called as hard margin SVM (since we have very strict constraints to
correctly classify each and every datapoint).
28
Support Vector Machine ASET
29
Support Vector Machine ASET
if ξi= 0,
the points can be considered as correctly classified.
else:
ξi> 0 , Incorrectly classified points.
31
Support Vector Machine ASET
• Types of kernels:
1. linear kernel
2. polynomial kernel
3. Radial basis function kernel (RBF)/ Gaussian Kernel
32
Support Vector Machine ASET
• Pros:
1. It is really effective in the higher dimension.
2. Effective when the number of features are more
than training examples.
3. Best algorithm when classes are separable
4. The hyperplane is affected by only the support
vectors thus outliers have less impact.
5. SVM is suited for extreme case binary
classification.
33
Support Vector Machine ASET
• cons:
1. For larger dataset, it requires a large amount of time
to process.
2. Does not perform well in case of overlapped classes.
3. Selecting, appropriately hyperparameters of the
SVM that will allow for sufficient generalization
performance.
4. Selecting the appropriate kernel function can be
tricky.
34
ASET
Thank You
35