Linear SVM Classification on Iris Dataset with Decision Boundary Visualization
Experiment
Linear SVM Classification on Iris Dataset with Decision Boundary Visualization
π― Objective
To implement a Linear Support Vector Machine (SVM) for binary classification on the Iris dataset and visualize the decision boundary and margin.
π Theory
A Linear SVM finds a hyperplane:
that separates two classes with maximum margin.
πΉ Margin Concept
- Margin = distance between two supporting hyperplanes
- Larger margin → better generalization
- Defined by support vectors
π Dataset: Iris Dataset
We use the famous Iris dataset.
- 3 classes: Setosa, Versicolor, Virginica
-
For simplicity → convert to binary classification:
- Setosa → 1
- Non-Setosa → 0
We use only 2 features for visualization:
- Sepal Length
- Sepal Width
π¬ Algorithm / Procedure
- Load dataset
- Convert into binary classification
- Select two features
- Train Linear SVM
- Plot decision boundary
- Plot margin and support vectors
π» Program
π Output
- Scatter plot of Iris data
- Straight decision boundary
- Two margin lines (parallel dashed lines)
- Support vectors highlighted
Discussion: Margin Concept
πΉ What is Margin?
Margin is the distance between the decision boundary and the closest data points (support vectors).
πΉ How is Margin Determined?
-
SVM selects hyperplane such that:
- Distance to nearest points is maximized
- Only support vectors influence this margin
πΉ Key Insight
π Margin depends on:
- Support vectors only
- Weight vector
- Regularization parameter
πΉ Effect of Margin on Classification
| Margin | Effect |
|---|---|
| Large Margin | Better generalization |
| Small Margin | Risk of overfitting |
πΉ Role of C in Margin
- Small C → Larger margin, allows some errors
- Large C → Smaller margin, fewer errors
Result
The Linear SVM model was successfully applied to the Iris dataset for binary classification.
- The model produced a linear decision boundary separating Setosa from Non-Setosa classes.
- The maximum margin hyperplane was observed along with parallel margin boundaries.
- Support vectors were identified as the critical points defining the margin.
- The classifier demonstrated effective separation with good generalization capability.

Comments
Post a Comment