Class Imbalance Handling Guide
Deal with rare events without fooling yourself.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
Help me handle a rare-event classification problem. Event rate and sample size: [EVENT_RATE_AND_SIZE]. Costs of errors: [ERROR_COSTS]. Model and tools: [MODEL_AND_TOOLS]. Walk through a decision path: 1. Check the metric first: accuracy is useless here; use PR AUC, recall at a fixed precision, or expected cost. 2. Try the cheap options first: class weights, threshold tuning on a validation set, and stratified splits. 3. Resampling (undersampling, oversampling, SMOTE): when each helps, and the rule to resample only the training fold, never the validation or test data. 4. Probability calibration after resampling, because predicted probabilities become distorted; show how to recalibrate. 5. Alternatives: anomaly detection, rules plus a model, active collection of more positives. 6. A table of experiments: Technique | Fold-level result | Calibration | Notes. Provide scikit-learn and imbalanced-learn code that keeps resampling inside a pipeline within cross-validation. Include a worked example of why 99 percent accuracy can mean nothing when 1 percent of cases are positive. End with a recommendation for my case and the evidence that would change it.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.