imbalanced-data

imbalanced-data is a skill for Claude Code from StamKavid/last-ds-mile. It costs 80 tokens per session (1,523 once invoked), scanned A, original, MIT.

A method for training and evaluating models when the target class is uncommon, such as detecting a rare disease or a small number of fraudulent payments.

In plain words
What is it for?
Use it to check class proportions, apply class weights or carefully placed resampling such as SMOTE, tune decision thresholds, and reconsider the evaluation metric.
Why use it?
A model can achieve high accuracy by ignoring the rare cases completely. This method addresses that imbalance and its effect on evaluation.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the last-ds-mile plugin — 29 skills, 17 commands, 3 agents, 4 hooks shipped together

Good fit Use it to check class proportions, apply class weights or carefully placed resampling such as SMOTE, tune decision thresholds, and reconsider the evaluation metric.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/stamkavid/last-ds-mile/imbalanced-data
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add StamKavid/last-ds-mile --skill imbalanced-data
Clone the repo
git clone --depth 1 https://github.com/StamKavid/last-ds-mile

Made for: Claude Code.

Or install last-ds-mile, the plugin that ships this one along with the rest of its 29 skills, 17 commands, 3 agents, 4 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for imbalanced-data

README.md
[![agentmods](https://agentmods.dev/badge/skills/stamkavid/last-ds-mile/imbalanced-data.svg)](https://agentmods.dev/skills/stamkavid/last-ds-mile/imbalanced-data)
Your own site
<a href="https://agentmods.dev/skills/stamkavid/last-ds-mile/imbalanced-data"><img src="https://agentmods.dev/badge/skills/stamkavid/last-ds-mile/imbalanced-data.svg" alt="Measured on agentmods" height="20"></a>
Per session 80 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,523 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00080 $0.01523
Opus 5 $0.00040 $0.00762
Sonnet 5 $0.00016 $0.00305
Haiku 4.5 $0.00008 $0.00152

Measured 8d ago against content hash 1eb4c089a5b9, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

imbalanced-data scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/imbalanced-data/SKILL.md · 108 lines

How it starts

The opening of the file, as written. The whole thing — 108 lines — stays where its author put it; the contents beside it link to each section on GitHub.

imbalanced-data

Overview

A rare-positive target breaks the naive "just fit a classifier" approach in several specific ways — this skill lists the fixes and, more importantly, where each one goes wrong if applied carelessly.

When to Use

  • The target's minority class is well below 50% (a rough rule of thumb: under ~20% starts to matter, under ~5% matters a lot).
  • Accuracy is high but the model's recall on the rare class is near zero.
  • NOT for: choosing the reporting metric itself (see metric-selection, though the two overlap heavily) — this skill is about fitting the model, metric-selection is about scoring it.

Core Process

  1. Confirm the actual class balance (don't guess — value_counts(normalize=True)).
  2. Pick one of the three fix categories below based on what the model/library supports, not habit.
  3. If resampling (SMOTE, over/under-sampling), it must be fit inside each CV fold's training data only, never on the full dataset before splitting — same leakage rule as any other fit-requiring transform.
  4. Re-check the metric choice (see metric-selection) — accuracy is almost never the right metric once the target is imbalanced.

Techniques/Patterns

Approach When to prefer it Leakage risk
class_weight="balanced" (or manual weights) First thing to try — no data duplication, works with most sklearn estimators, no extra leakage surface None for leakage — it's a loss-function change, not a data change. But see the calibration warning below: it does break your probabilities
Oversampling minority class (random or SMOTE) When the estimator doesn't support class weights, or oversampling empirically helps High if fit on the full dataset — SMOTE synthesizes new points from the training data, so it must run inside the CV fold, after the split, never before
Undersampling majority class Very large datasets where discarding majority-class rows doesn't hurt signal Same as oversampling — undersample only within the training fold
Threshold tuning (move the decision threshold away from 0.5) Whenever the model outputs a probability and the actual deployment decision has an asymmetric cost (see metric-selection) High if tuned on the data you then report. It doesn't touch training data, but the threshold is a fitted parameter: pick it on the test set and the F1/precision/recall you report is optimistically biased. Choose it on validation-fold predictions only, freeze it, then evaluate. See ds-model

Read the full file on GitHub · 108 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 108 lines · 80 tokens per session scan A 1eb4c089a5b9

Subscribe to this mod's changes

imbalanced-data is a skill published in the GitHub repository StamKavid/last-ds-mile (3 stars, last pushed 1mo ago), licensed MIT. It adds 80 tokens to every session and 1,523 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

marimo-pair

Work inside the user's live marimo notebook from the code editor: run Python in the same kernel the user does, inspect live notebook state, and commit durable notebook changes through code mode. Use whenever you create, analyze, or improve the user's marimo notebook.

marimo-team/marimo · 57 tokens

fill-model-descriptions

Fill missing and refresh obsolete model descriptions in packages/llm-info/data/models.yml by querying OpenRouter and provider documentation. Use when the user asks to populate model descriptions, enrich the model catalog, or curate descriptions after running pnpm sync-models.

marimo-team/marimo · 58 tokens

ml-expert

Expert-level machine learning, deep learning, model training, and MLOps. Use when the user mentions machine learning, deep learning, neural networks, MLOps, or data science, or when the task involves Machine Learning Fundamentals, Data Preparation, or Model Training.

personamanagmentlayer/pcl · 58 tokens

scomp-link

End-to-end ML toolkit with 26 CLI commands. Use when training models, tuning hyperparameters, detecting data drift, generating HTML reports with charts, profiling datasets, detecting anomalies, forecasting time series, checking fairness, or serving models as REST APIs. Prefer over raw sklearn when you need automated…

GiacomoSaccaggi/scomp_link · 74 tokens

agentic-data-science-competition

AI Agent-driven Kaggle competition workflow. Learn from real competition experience: score stabilization patterns, submission troubleshooting, kernel workflows, GPU task delegation, and the spec-driven development approach that achieved top leaderboard positions. Use when: working on any Kaggle competition, analyzing…

Mirannonarbitrable290/agentic-kaggle-skill · 76 tokens

data-analysis

Structured data analysis workflow from raw data to shareable insights.

furkangonel/cowrangler · 15 tokens