

- Precision = TP / (TP + FP) — of predicted positives, how many are correct.
- Recall (Sensitivity) = TP / (TP + FN) — of actual positives, how many we detected.
- F1 Score = 2 * (Precision * Recall) / (Precision + Recall) — harmonic mean of precision and recall; useful when both false positives and false negatives matter.
- ROC AUC — area under the ROC curve (TPR vs FPR) across thresholds; good for overall separability.
- PR AUC (Precision-Recall AUC) — often more informative than ROC AUC when the positive class is rare.
When the minority class detection is critical, prioritize precision, recall, F1 and PR AUC over plain accuracy. Use ROC AUC to compare separability and PR AUC to evaluate performance on rare positives.
- Data-level strategies (resampling): alter the training data distribution.
- Algorithm-level strategies: change the learning algorithm or loss to account for imbalance.

- Random oversampling: duplicate minority-class examples to rebalance classes. Pros: simple, effective for small imbalances. Cons: increases overfitting risk (exact duplicates).
- Random undersampling: remove majority-class examples to balance classes. Pros: faster training, less storage. Cons: may discard useful information.
- SMOTE (Synthetic Minority Oversampling Technique): synthesize new minority examples by interpolating between a sample and its k nearest minority neighbors. Pros: generates diverse minority examples, reduces overfitting compared with naive duplication. Cons: can create borderline/noisy samples and is sensitive to k and feature scaling.
Never oversample (including SMOTE) before splitting your data. Apply resampling only to the training set to avoid information leakage into your validation/test sets.

- Produces new, diverse minority examples (reduces overfitting compared with duplication).
- Can improve classifier sensitivity to minority examples.
- May generate noisy/borderline samples that cross class boundaries if classes overlap.
- Sensitive to the number of neighbors (k) and to feature scaling—standardize features first.
- For structured data (tabular), SMOTE works well; for images/text, use domain-specific augmentation.
- Class weighting: increase the loss contribution of the minority class by assigning larger weights to its examples. Many libraries (e.g., scikit-learn) support a
class_weightparameter. - Cost-sensitive learning: implement a custom loss that penalizes different types of errors differently; useful when you know relative costs of false positives vs false negatives.
- Ensemble and sampling-aware models: balanced random forests, boosting with class weights, or bagging combined with resampling can improve minority detection by aggregating multiple models and controlling sampling or weighting. Libraries to explore: XGBoost, LightGBM.

- If you have plenty of majority examples and training time matters: consider undersampling or ensemble methods with sampling.
- If discarding majority data is risky: use oversampling (SMOTE or variants) or class weighting.
- If misclassification costs are known or asymmetric: use cost-sensitive models or manual class weights.
- For image/text data: prefer domain-specific augmentation over SMOTE.
Validation and best practices
- Always split first: train/validation/test splits must be done before any resampling. Use stratified splitting to preserve class ratios in evaluation folds.
- Use appropriate metrics: precision, recall, F1, PR AUC, and ROC AUC. Select the metric that reflects business impact (e.g., recall for capturing fraud).
- Use stratified cross-validation when tuning hyperparameters to maintain class balance across folds.
- Monitor overfitting: when using oversampling, compare performance on validation/test sets to detect over-optimistic training results.
- For thresholded classifiers, tune decision thresholds using validation metrics that matter (e.g., maximize F1 or a weighted cost function).
- imbalanced-learn documentation (SMOTE and resampling)
- scikit-learn model weighting and metrics
- XGBoost documentation
- LightGBM documentation