0% found this document useful (0 votes)
62 views8 pages

SVM Implementation Walkthrough Guide

Uploaded by

Typical Things
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)
62 views8 pages

SVM Implementation Walkthrough Guide

Uploaded by

Typical Things
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
You are on page 1/ 8

PPT by:

Sripooja Mallam

Support Vector Machine (SVM)


Code walkthrough

Neil Gogte
KMIT

KMIT | DL, GenAI | 1


Basic SVM code

PPT by:
Sripooja Mallam

Using numpy and pandas to


implement SVM from scratch

KMIT | DL, GenAI | 2


Basic SVM code
Generate a synthetic cancer dataset
PPT by:
Sripooja Mallam

benign: Samples centered around [2, 2] to


represent benign cases.
malignant: Samples centered around [6, 6]
to represent malignant cases.

KMIT | DL, GenAI | 3


Basic SVM code Implement a basic linear SVM using
gradient descent.

PPT by:
Sripooja Mallam
Update Rules:
● If the condition is satisfied, apply regularization
to the weights.
● If misclassified, update weights and bias to
penalize the misclassification.

KMIT | DL, GenAI | 4


Basic SVM code

PPT by:
Sripooja Mallam

Predict method not invoked in


this code snippet

● Computes the dot product between input features X and learned weights
weights, subtracting the bias.
● Uses the np.sign function to classify:
○ Returns 1 for malignant and -1 for benign.
KMIT | DL, GenAI | 5
● Data Visualization:
Basic SVM code ○ Uses plt.scatter to plot benign and malignant
samples. c=labels ensures different colors for the
two classes. PPT by:
Sripooja Mallam
○ cmap='bwr': A color map where benign points are
blue, and malignant points are red.

● Hyperplane Visualization:
○ y_values = -(weights[0] *
x_values - bias) / weights[1]
calculates the decision
boundary (hyperplane
equation for SVM).
○ Plotted using plt.plot

KMIT | DL, GenAI | 6


Basic SVM code

PPT by:
Sripooja Mallam

KMIT | DL, GenAI | 7


Basic SVM code

PPT by:
Sripooja Mallam

Output is:
The sample [8.35 7.2 ] is classified as: Malignant

KMIT | DL, GenAI | 8

You might also like