Performance Comparison of SVM Kernels on Fashion MNIST Dataset

 

Experiment 

Performance Comparison of SVM Kernels on Fashion MNIST Dataset


🎯 Objective

To implement and compare SVM classifiers with Linear, Polynomial, and RBF kernels on the Fashion MNIST dataset and analyze their performance.


πŸ“š Theory

Support Vector Machines (SVM) use different kernel functions to handle different types of data:

  • Linear Kernel → Straight-line separation
  • Polynomial Kernel → Curved boundaries (controlled by degree)
  • RBF Kernel → Highly flexible, non-linear boundaries

πŸ“Š Dataset

We use the Fashion MNIST dataset.

  • 70,000 grayscale images (28×28 pixels)
  • 10 classes (T-shirt, shoe, bag, etc.)

πŸ”¬ Algorithm / Procedure

  1. Load dataset
  2. Normalize pixel values
  3. Flatten images into vectors
  4. Split into training and testing sets
  5. Train SVM with:
    • Linear kernel
    • Polynomial kernel
    • RBF kernel
  6. Evaluate accuracy
  7. Compare results

πŸ’» Program

import numpy as np from sklearn import svm, datasets from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split # Load dataset from keras.datasets import fashion_mnist (X_train, y_train), (X_test, y_test) = fashion_mnist.load_data() # Reduce size (for faster training in lab) X_train = X_train[:5000] y_train = y_train[:5000] X_test = X_test[:1000] y_test = y_test[:1000] # Normalize X_train = X_train / 255.0 X_test = X_test / 255.0 # Flatten images X_train = X_train.reshape(len(X_train), -1) X_test = X_test.reshape(len(X_test), -1) # -------- Linear SVM -------- linear_model = svm.SVC(kernel='linear') linear_model.fit(X_train, y_train) y_pred_linear = linear_model.predict(X_test) # -------- Polynomial SVM -------- poly_model = svm.SVC(kernel='poly', degree=3) poly_model.fit(X_train, y_train) y_pred_poly = poly_model.predict(X_test) # -------- RBF SVM -------- rbf_model = svm.SVC(kernel='rbf') rbf_model.fit(X_train, y_train) y_pred_rbf = rbf_model.predict(X_test) # Accuracy print("Linear SVM Accuracy:", accuracy_score(y_test, y_pred_linear)) print("Polynomial SVM Accuracy:", accuracy_score(y_test, y_pred_poly)) print("RBF SVM Accuracy:", accuracy_score(y_test, y_pred_rbf))

πŸ“ˆ  Output 

Linear SVM Accuracy: 0.823 Polynomial SVM Accuracy: 0.814 RBF SVM Accuracy: 0.859

πŸ“Š Comparison Analysis


πŸ”Ή 1. Linear Kernel

✅ Advantages:

  • Fast training
  • Works well for high-dimensional data
  • Less risk of overfitting

❌ Disadvantages:

  • Cannot capture complex patterns
  • Lower accuracy for image data

πŸ”Ή 2. Polynomial Kernel

✅ Advantages:

  • Can model curved boundaries
  • More flexible than linear

❌ Disadvantages:

  • Sensitive to degree parameter
  • Can overfit
  • Slower than linear

πŸ”Ή 3. RBF Kernel

✅ Advantages:

  • Handles complex non-linear data
  • High accuracy
  • Most widely used

❌ Disadvantages:

  • Computationally expensive
  • Requires tuning (C, gamma)
  • Can overfit if gamma is high

Key Insights

  • Image data like Fashion MNIST is highly non-linear
  • Linear SVM struggles to capture patterns
  • RBF kernel performs best due to flexibility

Result

The SVM classifiers with different kernels were successfully implemented and evaluated.

  • The RBF kernel achieved the highest accuracy, demonstrating its ability to model complex patterns in image data.
  • The Linear kernel performed faster but with lower accuracy.
  • The Polynomial kernel showed moderate performance, depending on the degree parameter.

Comments

Popular posts from this blog

Machine Learning Lab PCCSL508 Semester 5 KTU CS 2024 Scheme manual - Dr Binu V P

Lab Assignment-2

Lab Assignment-1