DEV Community

shakti tiwari
shakti tiwari

Posted on

ADASYN in imbalanced-learn: Adaptive Synthetic Sampling That Chases the Hard Minority Points

ADASYN in imbalanced-learn: Adaptive Synthetic Sampling That Chases the Hard Minority Points

Part of the SMOTE Family series. Previous: V6 SMOTEN. Next: V8 RandomOverSampler.

Disclaimer: Shakti Tiwari is NISM-Series-XII certified; not a SEBI-registered Research Analyst. Content is educational only.

Quick Answer

ADASYN (from imblearn.over_sampling import ADASYN) — the Adaptive Synthetic Sampling Approach of He, Bai, Garcia & Li (2008) — is the SMOTE variant that refuses to treat every minority point as equally worth copying. Where vanilla SMOTE sprays the same number of synthetic rows next to each minority instance, ADASYN first measures how hard each minority point is to learn and then spends its synthetic budget preferentially on the hard ones. A minority point is deemed "hard" when it is surrounded by many majority-class neighbours — i.e., it sits in the ambiguous, densely contested region of the class boundary. ADASYN generates more synthetic samples for exactly those points and fewer for the easy, well-separated ones. The mechanism is a normalized density distribution r derived from the count of majority neighbours of each minority point. [DERIVED summary of He, Bai, Garcia & Li 2008 + imbalanced-learn ADASYN implementation]

Why This Matters

Agar aap Nifty options trade karte ho, toh aap pehle se hi imbalanced duniya mein jeete ho. The price moves that actually move your P&L — a sharp expiry-day reversal, a volatility expansion that breaks a straddle, a failed breakdown that snaps back — are rare. The dull chop that fills most sessions is common. Train an XGBoost or LightGBM model naively on that history and it will quietly learn the lazy rule "predict the common class," because that minimises raw error while delivering a model that is useless for the trades that pay the bills.

Vanilla SMOTE (V1) fixed part of that by manufacturing synthetic minority rows — but it treated every minority row as equally valuable, generating the same count next to each. BorderlineSMOTE (V2) and SVMSMOTE (V3) got smarter by selecting boundary points and skipping the safe interior. But both still hand out synthetic samples roughly uniformly across whatever points they decide are "boundary." ADASYN takes the next conceptual step: it does not use a hard boundary/safe split at all. Instead it weights synthesis continuously by difficulty. A point drowning in majority neighbours gets a flood of synthetic neighbours; a point in clean minority space gets almost none. When minority difficulty is skewed — some points easy, some brutally hard — that proportional weighting is exactly what you want. [DERIVED from the conceptual motivation in He et al. 2008]

Our NSE stack is TWO-LAYER: Layer 1 = Dhan WebSocket live capture (shadow/predict-only); Layer 2 = EOD-audited XGBoost/LightGBM training core (walk-forward, cost-and-slippage). Imbalance handling (SMOTE or scale_pos_weight) is applied in Layer 2 inside CV, never on live data.

Research Question / Hypothesis

Research question: For a binary classifier trained on an imbalanced dataset, does difficulty-weighted over-sampling (ADASYN), which allocates synthetic samples proportionally to the local majority-neighbour density of each minority point, improve minority-class recall and balanced metrics (F1, G-mean) relative to uniform over-sampling (SMOTE), and under what data conditions does the gain appear or reverse?

Hypothesis (DERIVED): ADASYN should win when minority-class difficulty is heterogeneous — that is, when the hard minority points (those embedded in majority-dense regions) are concentrated, so that pouring synthetic samples into those contested zones genuinely thickens a learnable boundary. The gain should shrink toward vanilla SMOTE when difficulty is roughly uniform, and it should reverse into harm when the "hard" points are hard because they are mislabels or noise rather than genuine borderline signal — because ADASYN, unlike BorderlineSMOTE, has no noise-filtering step and will actually generate the most synthetic samples around an all-majority-surrounded (noise) minority point. The hypothesis is a derived expectation, not a measurement from this article.

Data & Methodology

We describe the canonical experimental shape used throughout the imbalanced-learn documentation and the over-sampling literature. No experiment is executed in this article — the snippet below is illustrative, taken from the imbalanced-learn API, and is shown only to anchor the method. [SOURCE: scikit-learn-contrib/imbalanced-learn repo, ADASYN docstring/example]

The pipeline shape is always:

  1. Stratified train/test split (never let ADASYN see the test set).
  2. Inside cross-validation only, fit ADASYN on the training fold and fit_resample.
  3. Train the estimator on the resampled fold; validate on the untouched test fold.
  4. Optionally wrap with Pipeline so resampling is never leaked.

Illustrative API usage (from imbalanced-learn docs — not run here):

from collections import Counter
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from imblearn.over_sampling import ADASYN
from imblearn.pipeline import Pipeline
from imblearn.metrics import classification_report_imbalanced

## Synthetic illustrative data — do not treat as a real market dataset
X, y = make_classification(
    n_classes=2, class_sep=2, weights=[0.1, 0.9],
    n_informative=3, n_redundant=1, flip_y=0,
    n_features=20, n_clusters_per_class=1,
    n_samples=1000, random_state=10,
)
print("Original dataset shape", Counter(y))
## Original dataset shape Counter({1: 900, 0: 100})

X_train, X_test, y_train, y_test = train_test_split(
    X, y, stratify=y, random_state=42
)

## default ADASYN: difficulty-weighted over-sampling
ada = ADASYN(
    n_neighbors=5,              # k used to estimate local difficulty
    n_neighbors_interpolation=5, # k used in the actual interpolation
    random_state=42,
)
X_res, y_res = ada.fit_resample(X_train, y_train)
print("Resampled shape", Counter(y_res))
## Resampled shape Counter({0: 900, 1: 900})  -- illustrative from repo example

pipe = Pipeline([
    ("adasyn", ADASYN(random_state=42)),
    ("clf", RandomForestClassifier(random_state=42)),
])
pipe.fit(X_train, y_train)
y_pred = pipe.predict(X_test)
print(classification_report_imbalanced(y_test, y_pred))
Enter fullscreen mode Exit fullscreen mode

Key constructor parameters [SOURCE: imbalanced-learn repo, ada_syn.py (ADASYN, n_neighbors, n_neighbors_interpolation)]:

  • n_neighbors (default 5) — the neighbourhood size used to estimate local difficulty. For each minority point, ADASYN finds its n_neighbors nearest neighbours in the combined feature space and counts how many belong to the majority class; that count over n_neighbors becomes the difficulty ratio r_i. A larger n_neighbors smooths the difficulty estimate across a wider region; a smaller one makes it sharper and noisier. [SOURCE: imbalanced-learn repo, _fit_resample density-ratio logic]
  • n_neighbors_interpolation (default 5) — the number of nearest minority neighbours used in the synthesis step. For each synthetic point, a partner x_zi is drawn at random from this minority-neighbour pool and the new row is interpolated between the seed and that partner. [SOURCE: imbalanced-learn repo, _fit_resample interpolation logic]
  • sampling_strategy (default "auto") — how much to oversample. With "auto", the minority class is resampled up to match the majority class count. This is how imbalanced-learn realises the original paper's balance-level parameter β (see Findings). [SOURCE: imbalanced-learn repo default]
  • random_state — for reproducibility of both the neighbour selection and the random interpolation gap.

A useful diagnostic the library exposes: ada.sampling_strategy_ — the per-class target counts actually used — and, after fit_resample, the resampled arrays themselves let you inspect where new points landed. Because ADASYN does not expose a per-seed "how many did I get" attribute the way BorderlineSMOTE exposes in_danger_indices_, the honest diagnostic is to diff the resampled arrays against the originals or to recompute r_i yourself. [SOURCE: imbalanced-learn repo, ADASYN attributes]

Results / Findings

Because this article does not run an experiment, the "findings" below are a synthesis of the primary sources, not measured numbers from this author's machine.

Finding 1 — ADASYN replaces the uniform budget with a weighted one. Vanilla SMOTE selects every minority point with equal probability and interpolates between two minority neighbours, so each minority point receives (approximately) the same number of synthetic children [SOURCE: Chawla et al. 2002]. ADASYN keeps the same interpolation rule but makes the count per point a function of difficulty. The original paper's stated goal is to "adaptively" shift the decision boundary toward the hard, minority-dense-in-majority regions rather than over-generalising the easy ones. [SOURCE: He, Bai, Garcia & Li 2008]

Finding 2 — The weighting comes from a normalized density distribution r. This is the load-bearing math, written here in full so you can see exactly where the parameters sit [DERIVED from He et al. 2008]:

Let m_s = number of minority samples, m_l = number of majority samples, k = n_neighbors, and β ∈ [0,1] = desired balance level (β = 1 means fully balanced).

  1. Total synthetic samples to generate: G = (m_l − m_s) · β.
  2. For each minority point x_i, let Δ_i = number of majority-class samples among its k nearest neighbours. Define r_i = Δ_i / k ∈ [0,1].
  3. Normalize: r̂_i = r_i / Σ_j r_j (so Σ_i r̂_i = 1).
  4. Samples generated for x_i: g_i = round(r̂_i · G).
  5. For each generated point, pick a random minority neighbour x_zi from the n_neighbors_interpolation nearest minority neighbours of x_i and set x_new = x_i + (x_zi − x_i) · λ, with λ ~ Uniform(0,1).

The key property: r_i is largest when a minority point is most engulfed by the majority class, so those points receive the most synthetic children. That is the precise sense in which ADASYN "generates more synthetic samples where the class boundary is ambiguous." [DERIVED]

Finding 3 — Worked numerical example (DERIVED). Take four minority points in 1-D and k = 5. Suppose each has these counts of majority neighbours among its 5 nearest neighbours:

Point Δ_i (majority neighbours) r_i = Δ_i/5 r̂_i (normalized)
x1 1 0.20 0.10
x2 2 0.40 0.20
x3 3 0.60 0.30
x4 4 0.80 0.40

Sum of r = 2.00, so normalized weights sum to 1. If sampling_strategy="auto" demands G = 10 new minority rows, the allocation is: g1 = 1, g2 = 2, g3 = 3, g4 = 4. The hardest point x4 (80% of its neighbours are majority) gets four times the synthetic budget of the easiest point x1. Vanilla SMOTE, by contrast, would hand each point ~2 or ~3 children — wasting half its budget on x1, which was already separable. This single table is the whole ADASYN idea in miniature. [DERIVED illustration]

Finding 4 — ADASYN is the only one of the family that weights continuously. SMOTE is uniform. BorderlineSMOTE applies a binary SAFE/DANGER/NOISE mask and then generates roughly uniformly across the DANGER set. SVMSMOTE uses SVM support vectors as a (roughly uniform) seed set. ADASYN applies no threshold — every minority point gets some children, allocated on a smooth gradient of difficulty. So among the variants we have covered, ADASYN is the only one that encodes "this point is twice/half as hard as that one" directly into the sample count. [DERIVED comparison of implementations in imbalanced-learn]

Finding 5 — There is no noise filter, and that is the deliberate trade-off. BorderlineSMOTE refuses to synthesise around NOISE points (those whose neighbours are all majority), on the theory that an all-majority-surrounded minority point is likely a mislabel. ADASYN has no such filter. Worse, in ADASYN a point with Δ_i = k (all neighbours majority) gets r_i = 1 — the maximum weight — and therefore the largest synthetic allocation. So if a minority point is a mislabel sitting in majority space, ADASYN will enthusiastically manufacture a crowd of synthetic children around the error. This is the central risk and the single most important reason ADASYN is not a blind default. [DERIVED from comparing ADASYN's r_i rule with BorderlineSMOTE's _in_danger_noise mask]

Finding 6 — β is realised through sampling_strategy. The original paper exposes a balance-level parameter β controlling how fully the classes are rebalanced. imbalanced-learn folds this into sampling_strategy: "auto" targets full balance (β ≈ 1); you can also pass a float (e.g., 0.3) or a dict to cap the ratio below full balance. Functionally, sampling_strategy sets the total G, while the distribution of G across minority points is always the difficulty-weighted r̂_i. [SOURCE: imbalanced-learn repo; DERIVED from He et al. 2008]

Reproducibility

To reproduce a real comparison you would, at minimum:

  1. Pick a fixed random_state everywhere (data split, ADASYN, estimator).
  2. Compare resamplers inside the same CV loop: SMOTE(), BorderlineSMOTE(kind="borderline-1"), and ADASYN(n_neighbors=5, n_neighbors_interpolation=5).
  3. Score with minority recall, precision, F1, and G-mean — not raw accuracy, which is misleading under imbalance.
  4. Always fit_resample on the training fold only.
  5. Because ADASYN has no noise filter, consider pairing it with Edited Nearest Neighbours (ENN) so the synthetic crowd around genuine noise gets pruned — an "ADASYN + ENN" combo.

The code sketch in Data & Methodology is the canonical shape from the imbalanced-learn documentation and is presented illustratively — it was not executed for this article, and its printed outputs are quoted from the library's own example pattern for reference. [SOURCE: imbalanced-learn repo docstring; not an experiment result of this author]

What Failed / Counter-Evidence

ADASYN is not a free lunch, and the honest literature plus implementation details say so.

  • It amplifies noise instead of suppressing it. As shown in Finding 5, ADASYN's maximum weight lands on all-majority-surrounded minority points. If those are mislabels (common in hand-labelled financial event sets — "was this really a reversal or just noise?"), ADASYN manufactures a synthetic neighbourhood around the mistake. BorderlineSMOTE and (partially) SVMSMOTE are safer here. [DERIVED from the r_i rule]
  • Blagus & Lusa (2013) show that SMOTE-family over-sampling can hurt on small or high-dimensional datasets, where the nearest-neighbour geometry is unreliable and synthetic points amplify noise rather than signal. ADASYN, which leans harder on neighbour counts than SMOTE does, inherits this failure mode and can worsen it: a noisy neighbour count produces a noisy difficulty weight. [SOURCE: Blagus & Lusa 2013]
  • When difficulty is uniform, ADASYN ≈ SMOTE. If every minority point has about the same majority-neighbour count, all r_i are equal, r̂_i is uniform, and ADASYN collapses to uniform over-sampling. You pay the extra neighbour search for no gain. [DERIVED]
  • Majority density is still the only signal. ADASYN decides "hard" purely from how many majority neighbours a point has. It does not check whether those majority neighbours are a coherent cluster or scattered noise, nor whether the minority point is a genuine frontier point or an outlier. A minority outlier near a dense majority blob is treated identically to a true borderline point. [DERIVED]
  • It can over-concentrate and create its own overfitting. By flooding synthetic points into contested regions, ADASYN can make the model overfit exactly the ambiguous zone it was trying to clarify — especially with a large G (full balance via "auto"). [DERIVED]

Limitations

  1. No noise filtering. The most important limitation: unlike BorderlineSMOTE, ADASYN does not skip all-majority-surrounded (likely mislabeled) minority points; it rewards them. Always sanity-check label quality before ADASYN, or pair with ENN. [DERIVED]
  2. Relies on neighbour geometry. Like all SMOTE variants, it assumes Euclidean proximity means semantic similarity. On high-dimensional, sparse, or heavily engineered feature spaces the k-nearest-neighbour counts become unreliable — the Blagus & Lusa 2013 critique. [SOURCE: Blagus & Lusa 2013; DERIVED]
  3. n_neighbors is a sensitivity knob. Too small and the difficulty estimate is noisy (one lucky/unlucky neighbour flips r_i); too large and it averages away genuine local structure. It must be tuned inside CV, not accepted at 5 blindly. [DERIVED]
  4. n_neighbors_interpolation is a second knob. It controls how locally the synthetic points are placed around each seed. Mismatch with the true neighbourhood scale hurts. [SOURCE: imbalanced-learn repo; DERIVED]
  5. Feature-space only. It operates in the raw feature space and assumes continuous Euclidean features. For mixed numeric/categorical data use SMOTENC; for all-categorical use SMOTEN. [SOURCE: imbalanced-learn repo]
  6. No separability guarantee. More synthetic points in a contested zone do not create a cleaner boundary if the true boundary is irreducible noise — they just thicken the fog. [DERIVED]
  7. β/balance level still matters. Full balance ("auto", β ≈ 1) may over-generate. Sometimes a partial ratio (e.g., sampling_strategy=0.3) or scale_pos_weight in XGBoost/LightGBM alone is better. [DERIVED]

Practical Takeaways

  • Reach for ADASYN when minority difficulty is skewed. If you believe the hard minority points are concentrated in majority-dense regions — the classic "ambiguous boundary" case — ADASYN's proportional weighting puts synthetic budget exactly where SMOTE wastes it.
  • Prefer it over SMOTE when you have already seen SMOTE over-generalise. If vanilla SMOTE gave you a model that still misses the rare, contested cases, ADASYN's difficulty weighting is the targeted upgrade. [DERIVED]
  • Pair with cleaning (ADASYN + ENN). Because ADASYN has no noise filter, follow it with Edited Nearest Neighbours to prune synthetic points that land in clearly majority territory. This single combo neutralises its biggest weakness. [DERIVED]
  • Tune n_neighbors and n_neighbors_interpolation as hyperparameters inside CV; do not accept defaults on real data.
  • Watch label quality. ADASYN punishes sloppy labels hardest. Clean or audit your minority labels first. [DERIVED]
  • Never resample the test set. Resample inside the training fold only, ideally via imblearn.pipeline.Pipeline so it composes cleanly with scaling and the classifier.
  • Compare against the cheap baseline. Before reaching for any SMOTE variant, try scale_pos_weight (XGBoost/LightGBM) or class weights — sometimes that alone closes the gap without synthesising a single row.
  • In our stack, all of this lives in Layer 2 (EOD-audited training), never in Layer 1 (live Dhan capture).

FAQ

Q1. How is ADASYN different from vanilla SMOTE?
A1. SMOTE gives every minority point roughly the same number of synthetic children. ADASYN first estimates each minority point's difficulty (how many of its n_neighbors nearest neighbours are majority), then generates more synthetic children for the harder points and fewer for the easy ones. Same interpolation rule, smarter budget allocation. [DERIVED from He et al. 2008 + imbalanced-learn]

Q2. What exactly is the density distribution r?
A2. For each minority point x_i, r_i = Δ_i / k where Δ_i is the count of majority-class neighbours among its k = n_neighbors nearest neighbours. After normalizing r̂_i = r_i / Σ_j r_j, the number of synthetic samples for x_i is g_i = round(r̂_i · G), with G the total to generate. So r is literally "fraction of my neighbours that are majority." [DERIVED from He et al. 2008]

Q3. What do n_neighbors and n_neighbors_interpolation do?
A3. n_neighbors (default 5) sets the neighbourhood size used to measure difficulty — the k in r_i = Δ_i / k. n_neighbors_interpolation (default 5) sets how many nearest minority neighbours are used in the synthesis step, from which the interpolation partner x_zi is randomly chosen. They are independent knobs. [SOURCE: imbalanced-learn repo]

Q4. Is ADASYN always better than SMOTE or BorderlineSMOTE?
A4. No. It wins when minority difficulty is heterogeneous and the hard points are genuine borderline signal. It can hurt when the "hard" points are mislabels (it has no noise filter and rewards all-majority-surrounded points with the most synthetic samples), on small/high-dimensional data (Blagus & Lusa 2013), or when difficulty is roughly uniform (it collapses to SMOTE). [DERIVED from He et al. 2008 + Blagus & Lusa 2013]

Q5. Why does ADASYN risk amplifying noise?
A5. Because its weight r_i = Δ_i / k is maximal (equals 1) when all k neighbours are majority — exactly the NOISE case that BorderlineSMOTE skips. So a mislabeled minority point in majority space gets the largest synthetic allocation. Always audit labels or pair with ENN. [DERIVED]

Q6. Can I use ADASYN with categorical features?
A6. ADASYN works in continuous Euclidean space. For mixed numeric/categorical data use SMOTENC; for all-categorical use SMOTEN — both from imblearn.over_sampling. [SOURCE: imbalanced-learn repo]

Q7. Should I apply it to live trading data?
A7. No — apply any over-sampling inside the training/CV loop of your audited model core, never on live inference. Our NSE stack keeps resampling strictly in Layer 2. [DERIVED from the two-layer engine design]

Q8. What comes after ADASYN?
A8. V8 RandomOverSampler — the simplest over-sampler of all: it duplicates existing minority rows uniformly at random, with no synthesis and no neighbour geometry. A useful cheap baseline against which every SMOTE variant (including ADASYN) should be measured. [SOURCE: imbalanced-learn repo]

TL;DR

  • ADASYN (from imblearn.over_sampling import ADASYN) is difficulty-weighted over-sampling: it generates more synthetic minority samples for points that are harder (more majority neighbours), unlike SMOTE's uniform budget. [DERIVED from He et al. 2008]
  • The weight is a normalized density distribution r: r_i = Δ_i / k, normalized to r̂_i, then g_i = round(r̂_i · G). k = n_neighbors. [DERIVED]
  • n_neighbors (default 5) sets the difficulty-estimation neighbourhood; n_neighbors_interpolation (default 5) sets the interpolation partner pool. [SOURCE: imbalanced-learn repo]
  • It helps when minority difficulty is skewed and the hard points are genuine borderline signal. [DERIVED]
  • Its big risk: no noise filter — all-majority-surrounded (likely mislabeled) points get the most synthetic samples, so ADASYN can amplify noise. Pair with ENN; tune n_neighbors. [DERIVED]
  • Always resample inside CV only; next in series: V8 RandomOverSampler. Previous: V6 SMOTEN.

📚 Related Articles

👤 About the Author



Name:
Shakti Tiwari

Role:
Nifty Option Trader, XGBoost Expert

Cert:
NISM-Series-XII (Securities Markets Foundation)

Knows:
XGBoost · LightGBM · Options Trading · Machine Learning · Walk-forward Validation



Profiles:
about.me ·
optiontradingwithai.in ·
github ·
whatsapp ·
x/twitter

Sources

  • [SOURCE] He, H., Bai, Y., Garcia, E. A., & Li, S. (2008). ADASYN: Adaptive synthetic sampling approach for imbalanced learning. IEEE International Joint Conference on Neural Networks (IJCNN 2008 / IEEE World Congress on Computational Intelligence), pp. 1322–1328. — original ADASYN algorithm: difficulty ratio r_i = Δ_i / k, normalized density distribution, and difficulty-weighted synthetic sample allocation g_i = r̂_i · G.
  • [SOURCE] scikit-learn-contrib/imbalanced-learn GitHub repository — imblearn/over_sampling/_adasyn.py (ADASYN, n_neighbors, n_neighbors_interpolation, sampling_strategy, _fit_resample density-ratio and interpolation logic). Primary source for the implementation described.
  • [SOURCE] Chawla, N. V., Bowyer, K. W., Hall, L. O., & Kegelmeyer, W. P. (2002). SMOTE: Synthetic Minority Over-sampling Technique. Journal of Artificial Intelligence Research, 16, 321–357. — vanilla SMOTE baseline (uniform over-sampling).
  • [SOURCE] Han, H., Wang, W.-Y., & Mao, B.-H. (2005). Borderline-SMOTE: A New Over-Sampling Method in Imbalanced Data Sets Learning. ICIC 2005, LNCS 3644, 878–887. — BorderlineSMOTE SAFE/DANGER/NOISE mask, the contrast point for ADASYN's lack of a noise filter.
  • [SOURCE] Blagus, R., & Lusa, L. (2013). SMOTE can degrade performance on small, high-dimensional datasets (cautionary note on over-sampling). — counter-evidence on small/high-dimensional data, which ADASYN inherits and can worsen.
  • [DERIVED] The full r_i/r̂_i/g_i derivation, the 1-D four-point worked table, the ADASYN-vs-SMOTE/BorderlineSMOTE/SVMSMOTE comparison (continuous weighting, no threshold), the noise-amplification insight (r_i = 1 for all-majority-surrounded points), and the imbalanced-learn sampling_strategy ↔ β mapping — all derived from the cited sources.

Author / Canonical

Written for Shakti Tiwari — Nifty Option Trader, XGBoost Expert (optiontradingwithai.in). Part of the SMOTE Family series (V7 of V8). This is educational content; not investment advice and not SEBI-registered research.

Resources & Links

Top comments (0)