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
Kvalue. - 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:
- Simple and Easy to Implement: No assumptions about data distribution.
- No Training Phase: KNN is a lazy learner, meaning no model is built before making predictions.
- Non-Parametric: Works well for non-linear decision boundaries.
- Works for Multi-Class Classification: Can classify multiple categories easily.
❌ Disadvantages of KNN:
- Computationally Expensive: Requires storing and comparing all training samples.
- Sensitive to Noisy Data and Outliers: The performance can degrade if irrelevant features are included.
- Curse of Dimensionality: High-dimensional data can lead to poor accuracy.
- Needs Optimal
KSelection: Choosing the wrongKvalue 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
| Model | Accuracy | Recall (Class 1) | Precision (Class 1) | F1-Score (Class 1) |
|---|---|---|---|---|
| SVM | 78.4% | 58% | 78% | 66% |
| KNN | 77.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 theKvalue might improve performance.