Imbalanced Anomaly Detector
SMOTE, cost-sensitive learning and gradient-boosted ensembles
Machine Learning
Overview
When the number of normal instances significantly outweighs the abnormal ones, models become biased toward the majority class. Inspired by manufacturing anomaly detection, I conducted a personal project identifying low-quality wine by comparing anomaly detection techniques on a highly imbalanced dataset.
Dataset
The Wine Quality Dataset (Red Wine) was reframed as anomaly detection:
- Normal Class (0): Wine quality score ≤ 6 — 1,382 instances
- Abnormal Class (1): Wine quality score > 6 — 217 instances
This yields a roughly 85:15 class imbalance.

EDA


Evaluation — Equal Error Rate
Accuracy is misleading with severe class imbalance — predicting everything as Normal yields 86%. Instead, we use the Equal Error Rate (EER): the point on the ROC curve where FAR (False Acceptance Rate) = FRR (False Rejection Rate). A lower EER indicates a more stable model.
Results


| Model | EER | Result |
|---|---|---|
| Weighted KNN | 0.1915 | Best |
| KNN | 0.2170 | Excellent |
| Isolation Forest | 0.4432 | Good |
| PCA (Autoencoder) | 0.4468 | Good |
| KMeans | 0.5092 | Average |
| One-Class SVM | 0.5314 | Average |
| ABOD | 0.6264 | Poor |
| Mixture of Gaussians | 0.7656 | Worst |
Key Takeaways
- Distance-Based Methods Won: KNN and Weighted KNN dominated. The local distance weighting of Weighted KNN pushed EER below 0.20.
- Dedicated Outlier Detectors Struggled: One-Class SVM and ABOD performed averagely or poorly on this dataset.
- Isolation Forest achieved a modest 0.4432, consistent with its reputation as a robust baseline.
Anomaly detection requires significant trial and error. Complex specialized models do not always outperform simpler distance-based models depending on the data distribution.