Challenge

Supervised Learning - Classification Week 8 Challenge

1. Applying K-Nearest Neighbors (KNN) to the "Surface Defects in Stainless Steel Plates" Dataset

I will now:

  • Preprocess the dataset (scaling features, handling missing values).
  • Apply KNN classifier with an optimal K value.
  • Evaluate performance using accuracy, precision, recall, and F1-score.
  • Compare results with SVM to identify differences.

2. Pros and Cons of KNN

✅ Advantages of KNN:

  1. Simple and Easy to Implement: No assumptions about data distribution.
  2. No Training Phase: KNN is a lazy learner, meaning no model is built before making predictions.
  3. Non-Parametric: Works well for non-linear decision boundaries.
  4. Works for Multi-Class Classification: Can classify multiple categories easily.

❌ Disadvantages of KNN:

  1. Computationally Expensive: Requires storing and comparing all training samples.
  2. Sensitive to Noisy Data and Outliers: The performance can degrade if irrelevant features are included.
  3. Curse of Dimensionality: High-dimensional data can lead to poor accuracy.
  4. Needs Optimal K Selection: Choosing the wrong K value can significantly affect accuracy.

KNN Classification Results for Surface Defects in Stainless Steel Plates:

  • Accuracy: 77.89%
  • Classification Report:

precision recall f1-score support

0 0.79 0.88 0.83 246

1 0.75 0.60 0.67 143


accuracy 0.78 389

macro avg 0.77 0.74 0.75 389

weighted avg 0.78 0.78 0.77 389

Comparison of KNN vs SVM

ModelAccuracyRecall (Class 1)Precision (Class 1)F1-Score (Class 1)
SVM78.4%58%78%66%
KNN77.89%60%75%67%

Key Differences:

  • KNN slightly underperforms SVM in accuracy (77.89% vs. 78.4%).
  • KNN has a slightly better recall for classifying faulty cases (60%) compared to SVM (58%).
  • SVM has a higher precision (78%) than KNN (75%), meaning it misclassifies fewer non-faulty cases.


Key Takeaways:

  • SVM is more reliable for precise classifications.
  • KNN is slightly better for detecting more faulty cases (higher recall for Class 1).
  • KNN is computationally expensive for large datasets, whereas SVM handles large data better with kernel tricks.
  • KNN is sensitive to the choice of K, so tuning the K value might improve performance.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.