Implementation of linear SVM using Scikit-learn with Visualization
Experiment
Implementation of linear SVM using Scikit-learn with Visualization
๐ฏ Objective
To implement Support Vector Machine (SVM) using Scikit-learn and visualize the decision boundary and support vectors.
๐ Theory
Support Vector Machine (SVM) is a supervised learning algorithm used for classification. It finds the optimal hyperplane that separates classes with maximum margin.
Key Points:
- Works well for linearly separable data
- Uses support vectors to define boundary
-
Can use different kernels:
- Linear
- Polynomial
- RBF
๐ Dataset
We use a simple 2D dataset:
| x₁ | x₂ | Class |
|---|---|---|
| 2 | 2 | 0 |
| 3 | 3 | 0 |
| 4 | 4 | 0 |
| 6 | 6 | 1 |
| 7 | 7 | 1 |
| 8 | 8 | 1 |
๐ฌ Algorithm / Procedure
- Import libraries
- Create dataset
- Train SVM model using linear kernel
- Plot data points
- Plot decision boundary
- Highlight support vectors
๐ป Program
๐ Output
- Scatter plot of data points
- Decision boundary (solid line)
- Margin lines (dashed)
- Support vectors (circled points)
✅ Result
The SVM classifier was successfully implemented using Scikit-learn, and the decision boundary along with support vectors was visualized

Comments
Post a Comment