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

Support Vector Machine (SVM)

Uploaded by

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

Support Vector Machine (SVM)

Uploaded by

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

Describe the working behavior of Support Vector Machine with an

example

Support Vector Machine (SVM) Working Behavior

Support Vector Machine (SVM) is a supervised machine learning algorithm used for
classification and regression tasks. It is particularly effective for high-dimensional datasets
and works well for both linear and non-linear data.

1. Objective of SVM

The main goal of SVM is to find the optimal hyperplane that maximally separates data
points of different classes. The hyperplane is chosen such that it has the largest margin
between the closest points (support vectors) of the two classes.

2. Key Concepts

● Hyperplane: A decision boundary separating different classes in the feature space.


● Support Vectors: The data points closest to the hyperplane. These points influence
the position and orientation of the hyperplane.
● Margin: The distance between the hyperplane and the nearest data points from
either class. SVM maximizes this margin for better generalization.
3. Steps in SVM Classification (Working)

1. Input Data: The algorithm takes labeled data points (features and corresponding
class labels).
2. Choose Kernel Function: Based on the data, select a kernel function to transform it
into a higher-dimensional space (if necessary) to make it linearly separable.
○ Common kernels: Linear, Polynomial, Radial Basis Function (RBF), Sigmoid.
3. Construct Hyperplane: Find the hyperplane that separates the classes with the
maximum margin.
4. Classify New Data: Use the hyperplane to predict the class of new data points.

Why is SVM Effective?

● Robustness: Focuses only on support vectors, ignoring the influence of other data
points.
● Flexibility: Works for both linearly and nonlinearly separable data using kernel tricks.
● High-dimensional data: Handles datasets with many features effectively.

By maximizing the margin, SVM ensures that the model is not only accurate but also
generalizes well to unseen data, reducing overfitting.

Applications of SVM

1. Text Classification: Spam detection, sentiment analysis, and topic categorization.


2. Image Recognition: Facial recognition, object detection, and handwritten digit
recognition.
3. Bioinformatics: Gene classification and protein structure prediction.
4. Healthcare: Disease diagnosis, medical image analysis, and drug discovery.
5. Finance: Credit risk assessment and stock price prediction.
6. Anomaly Detection: Fraud detection and network intrusion prevention.

SVM excels in tasks involving high-dimensional data and non-linear separations.

Example: Email Spam Classification

Problem: Classify emails as "Spam" or "Not Spam" based on features like word frequency,
presence of links, etc.
1. Input Data: Feature set includes attributes like:
○ Frequency of the word "offer."
○ Number of links in the email.
○ Use of capitalized words.

2. Visualization: Plot the data in a 2D/3D space using two or more features.
3. Training the SVM:
○ If the data is linearly separable, SVM identifies the hyperplane with maximum
margin.
○ If not, the kernel function (e.g., RBF) maps data into a higher-dimensional
space where it becomes linearly separable.
4. Hyperplane and Margin:
○ SVM constructs a decision boundary separating "Spam" and "Not Spam."
○ The closest emails to the boundary are the support vectors.
5. Classification:
○ For a new email, calculate its position relative to the hyperplane.
○ Assign "Spam" or "Not Spam" based on which side of the hyperplane it lies.
Python Code: Email Spam Classification with SVM
Here’s a Python example of using SVM with the scikit-learn library for email spam
classification:
Key Notes

1. The dataset in this example is small and illustrative. In real-world applications,


datasets are larger and may require preprocessing.
2. You can experiment with different kernel functions (e.g., rbf, poly) by changing the
kernel parameter in SVC.
3. C controls the trade-off between achieving a low error on the training set and
maintaining a large margin.

You might also like