0% found this document useful (0 votes)
18 views

SVM LAB.7

The document provides an overview of Support Vector Machine (SVM), a supervised learning algorithm used for classification and regression tasks. It details its applications in various fields such as image processing, medical diagnosis, text recognition, and finance, along with its advantages and disadvantages. Additionally, it includes mathematical concepts related to SVM and a stepwise implementation example using Python.

Uploaded by

2205437
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

SVM LAB.7

The document provides an overview of Support Vector Machine (SVM), a supervised learning algorithm used for classification and regression tasks. It details its applications in various fields such as image processing, medical diagnosis, text recognition, and finance, along with its advantages and disadvantages. Additionally, it includes mathematical concepts related to SVM and a stepwise implementation example using Python.

Uploaded by

2205437
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Applications Development Laboratory (CS33002), Spring 202

Applications Development Laboratory (ADL)


Group Work

Roll Numbers 2205437 , 2205472 , Branch/Section: CSE 19


2205481 , 22052507
Name in Capital ADITI KUMAR , JUNAID UL ISLAM , NAVNEET KUMAR MAHTO
(Separated by SHREYANSH
Commas)

Support Vector Machine

What is Support Vector Machine (SVM)?

Support Vector Machine (SVM) is a supervised learning algorithm used for classification and regression
tasks. It works by finding the optimal hyperplane that best separates different classes in a dataset while
maximizing the margin between the nearest data points (support vectors).

Where is it used?

Real life usage of SVM are as follows :-

1. Image Processing & Computer Vision

● Face Detection: SVM classifies parts of an image as face or non-face.


● Handwriting Recognition: Used to recognize handwritten characters.
● Object Detection: Helps in identifying objects in images.

2. Medical Diagnosis

● Cancer Detection: SVM is used in classifying medical images (e.g., detecting breast cancer in
mammograms).
● Disease Prediction: Helps in diagnosing diseases based on patient data.

3. Text & Speech Recognition

● Spam Filtering: SVM can classify emails as spam or not spam.


● Sentiment Analysis: Used to determine positive or negative sentiment in texts.
● Speech Recognition: Helps in voice-based classification tasks.

4. Financial Sector

● Stock Market Analysis: Used to predict stock price movements.


● Fraud Detection: Helps in identifying fraudulent transactions in banking.

Page 1
Applications Development Laboratory (CS33002), Spring 202

Advantages of SVM ?

1.Effective in high-dimensional spaces


2.Robust to overfitting (with regularization)
3.Works for both linear & non-linear data (using kernel trick)
4.Effective for small and medium-sized datasets
5.Finds the optimal hyperplane with maximum margin
6.Handles outliers to some extent (soft-margin SVM)
7.Works well for structured and unstructured data

Dis-Advantages of SVM ?

1.Slow training for large datasets (not scalable)


2.High memory usage (due to storing support vectors)
3.Difficult to tune hyperparameters (e.g., kernel, C, gamma)
4.Not suitable for highly noisy data (sensitive to overlapping classes)
5.Interpreting results is complex (especially with non-linear kernels)
6.Kernel selection is tricky (wrong choice can reduce performance)

Techniques/Mathematics/Statistics/Concepts used in SVM ?

1.Hyperplane and Decision Boundary – A hyperplane is the optimal boundary that separates different
classes.
2.Support Vectors – These are the closest data points to the hyperplane that influence its position.
3.Margin Maximization – SVM aims to maximize the distance (margin) between the hyperplane and support
vectors for better generalization.
4.Lagrange Multipliers & Dual Formulation – Used to transform the optimization problem into a solvable
form.
5.Kernel Trick – A method to transform non-linearly separable data into a higher-dimensional space for
better separation.
Types of Kernels:

● Linear Kernel – Used for linearly separable data.


● Polynomial Kernel – Maps data to a higher polynomial dimension.
● Radial Basis Function (RBF) Kernel – Maps data into infinite dimensions for complex separations.
● Sigmoid Kernel – Similar to a neural network activation function.

6.Soft Margin vs. Hard Margin – Soft margin allows some misclassification, while hard margin strictly
separates classes.
7.Regularization Parameter (C) – Controls the trade-off between margin maximization and classification
accuracy.
8.Convex Optimization – A mathematical technique to ensure the best hyperplane is found.
9.Hinge Loss Function – A loss function used in SVM that penalizes misclassified points.

Page 2
Applications Development Laboratory (CS33002), Spring 202
10.Quadratic Programming – A mathematical optimization method used to solve SVM’s constrained
optimization problem.

Implementation of SVM using Python (Stepwise with comments with the same lung cancer data)

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.inspection import DecisionBoundaryDisplay
# Load dataset from CSV
file_path = "/content/LungNum.csv" # Replace with your actual file path
df = pd.read_csv(file_path)
df = df.drop(columns='Patient_ID')
# Select features and target (modify column names as needed)
X = df.iloc[:, :-1].values # Assuming all but the last column are features
y = df.iloc[:, -1].values # Assuming the last column is the target
# Normalize features
scaler = StandardScaler()
X = scaler.fit_transform(X)
# Split dataset (optional, for training and testing)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
from sklearn.decomposition import PCA
from sklearn.svm import SVC
from sklearn.inspection import DecisionBoundaryDisplay
import matplotlib.pyplot as plt

# Reduce X_train to 2D using PCA


pca = PCA(n_components=2)
X_train_pca = pca.fit_transform(X_train)
X_test_pca = pca.transform(X_test) # Apply same transformation to test data

# Train a new SVM model on 2D data


svm_2d = SVC(kernel="linear") # Change kernel as needed
svm_2d.fit(X_train_pca, y_train)
# Plot decision boundary
plt.figure(figsize=(8, 6))
DecisionBoundaryDisplay.from_estimator(

Page 3
Applications Development Laboratory (CS33002), Spring 202
svm_2d, X_train_pca, response_method="predict", cmap=plt.cm.Spectral,
alpha=0.8
)
plt.scatter(X_train_pca[:, 0], X_train_pca[:, 1], c=y_train, edgecolors="k")
plt.title("Decision Boundary of SVM (Reduced to 2D)")
plt.show()

OUTPUT:

Page 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy