param087/agent-ml-skills/imbalanced-data
Claude Code and agent skill by param087/agent-ml-skills
- community
Checking that the SKILL.md file is still in the repository.
Use when the target is rare (fraud, churn, disease, anomalies). Covers correct metrics, resampling (SMOTE/undersampling), class weights, threshold tuning, and avoiding the accuracy trap and resampling leakage.
Install
npx vskill@latest install param087/agent-ml-skills/imbalanced-dataSKILL.md
The same SKILL.md was published earlier as param087/agent-ml-skills/imbalanced-data.
Imbalanced Data
Overview
When positives are rare, naive training and naive metrics both mislead. A model that always predicts "negative" can score 99% accuracy and catch zero fraud. Handle imbalance at three levels: metric, algorithm, and threshold — and resample inside cross-validation, never before.
When to use
- Class ratio is skewed (e.g., 95/5 or worse).
- Catching the rare class matters (fraud, defaults, rare disease, defects).
Step 1 — Fix the metric first
Drop accuracy and ROC-AUC-as-sole-metric. Prefer:
- PR-AUC (average precision) — most informative for rare positives.
- Recall @ fixed precision — "catch X% of fraud while keeping false alarms tolerable."
- F1 / Fβ — β>1 weights recall when misses are costly.
Step 2 — Algorithm-level handling
| Technique | How | When | |
|---|---|---|---|
| Class weights | class_weight="balanced" / scale_pos_weight | First choice — no data duplication | |
| Undersample majority | RandomUnderSampler | Lots of data, majority redundant | |
| Oversample minority | SMOTE / ADASYN | Limited minority samples | |
| Combine | SMOTE + Tomek/ENN | Noisy boundaries |
Class weights are the cheapest, leak-free first move:
Step 3 — Resample INSIDE the pipeline (no leakage)
Resampling before CV leaks synthetic neighbors across the split and inflates scores. Use imblearn's pipeline so SMOTE fits on training folds only:
Step 4 — Tune the decision threshold
Default 0.5 is almost always wrong for imbalanced problems. Pick the threshold from the validation PR curve to hit your precision/recall target:
Pitfalls
- Accuracy as the metric — the central trap.
- SMOTE before train/test split — leaks synthetic points; scores look great, production fails.
- Resampling the test set — evaluate on the real (imbalanced) distribution.
- Oversampling then ignoring the threshold — probabilities shift; recalibrate/tune the cut.
- Synthetic samples on categorical/high-dim data — SMOTE assumes meaningful interpolation; use SMOTENC or class weights instead.
Hand-off
A model trained with leak-free resampling/weights, scored with PR-AUC and a tuned threshold via model-evaluation, ready for model-serving.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/imbalanced-data/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/param087/agent-ml-skills/imbalanced-data)