Imbalanced-learn

imbalanced-learn

A scikit-learn compatible library for handling class imbalance with resampling such as SMOTE and balanced ensemble methods.

ActiveBeginnerv0.14.2MITMachine Learning Frameworks & Libraries

Official documentationTry the examples

Basic information

NameImbalanced-learn
Full nameimbalanced-learn
CategoryMachine Learning Frameworks & Libraries
DeveloperThe scikit-learn-contrib community
Release yearNot specified
Official websiteimbalanced-learn.org
GitHub repositoryscikit-learn-contrib/imbalanced-learn
Official documentationNot specified
Package on PyPIimbalanced-learn
LicenseMIT (Licence file)
Project statusActive Had a release in the last 12 months
Latest version7 June 2026 (version 0.14.2)
Programming languagePython
Operating systemsOS Independent (as declared by the package on PyPI)
Required Python version>=3.10
Difficulty levelBeginner

Data last checked: 21 November 2026 — source: PyPI JSON API (2026-11-21)

Overview

imbalanced-learn provides methods to oversample the minority class (SMOTE, ADASYN and others), undersample the majority class and combine both, balanced ensemble classifiers, and metrics suited to imbalanced data.

It integrates with its own Pipeline, which ensures that resampling is applied only inside each cross-validation fold, avoiding data leakage, a common mistake in medical research.

When to choose it? Choose it when an important class is rare in tabular data, applying resampling only inside cross-validation.

Uses

Main uses

  • Oversampling the rare class (SMOTE)
  • Undersampling the majority class
  • Balanced ensemble classifiers

Scientific fields

  • Medicine and rare disease diagnosis
  • Fraud detection

Suitable project types

  • Classifying imbalanced medical data
  • Detecting fraudulent transactions

Research applications

  • Comparing resampling methods with correct cross-validation

Imbalanced dataClassical machine learning

Technical features

A feature is shown as "Supported" only if it is documented in the library's official documentation; anything we have not verified is shown as "Not specified".

CPU supportSupported
GPU supportNot supported
CUDA compatibilityNot supported
Distributed training or computingNot supported
Automatic differentiation (Autodiff)Not supported
Model deploymentNot applicable
Pre-trained modelsNot applicable
Supported data typesNumPy arrays and pandas tables
Integration with other librariesScikit-learn, Pandas
Flexibility (editorial estimate)Medium
Performance (editorial estimate)Adequate
Community (editorial estimate)Medium
Documentation quality (editorial estimate)Good documentation

Installation and running

Shell
pip install imbalanced-learn

Compatibility: Python >=3.10 — according to the package data on PyPI, checked on 21 November 2026

Installing inside a virtual environment (venv or conda) is recommended. If you need compatibility with a specific CUDA version or operating system, refer to the official documentation, because this information changes with every release.

Code examples

Examples marked "Run and tested" were actually run, with their output, test date and library versions recorded; the others need a GPU or model downloads, so they were not run in the test environment.

MediumSMOTE inside the pipeline without leakageRun and tested

Goal: Balancing classes on the training data only, in each fold.

Python — example.py
from collections import Counter
from imblearn.over_sampling import SMOTE
from imblearn.pipeline import make_pipeline
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, cross_val_score

X, y = make_classification(n_samples=2000, weights=[0.95, 0.05], n_features=10, random_state=0)
print("Class distribution:", {int(k): v for k, v in sorted(Counter(y).items())})
cv = StratifiedKFold(5, shuffle=True, random_state=0)
base = cross_val_score(LogisticRegression(max_iter=1000), X, y, cv=cv, scoring="recall")
smote = cross_val_score(make_pipeline(SMOTE(random_state=0), LogisticRegression(max_iter=1000)),
                        X, y, cv=cv, scoring="recall")
print(f"Recall of the rare class without balancing: {base.mean():.3f}")
print(f"Recall with SMOTE inside the pipeline: {smote.mean():.3f}")

Code explanation

SMOTE must not be applied before splitting, otherwise samples generated from the test data appear in training. The imbalanced-learn Pipeline applies resampling during fit only, so the validation fold keeps its real distribution.

Requirements

Shell
pip install imbalanced-learn scikit-learn

How to run

Save the code in a file example.py then run it:

Shell
python example.py

Output recorded during testing

Class distribution: {0: 1892, 1: 108}
Recall of the rare class without balancing: 0.879
Recall with SMOTE inside the pipeline: 0.926

This example was actually run and tested on 21 November 2026 on a CPU — imbalanced-learn 0.14.2, scikit-learn 1.9.1, python 3.13.18

Example page

All Imbalanced-learn examples in the Code Explorer

Pros

  • The same scikit-learn API
  • Its Pipeline prevents data leakage when resampling

Limitations

  • Resampling does not suit every problem and can generate unrealistic samples
  • Designed mainly for tabular data

References and verification

  • Package page on PyPI (source of the version, licence and release date) Checked directly

    https://pypi.org/project/imbalanced-learn/

    Checked on: 21 November 2026 — version checked: 0.14.2 — reviewed by: the DLArabic team

  • Official website A link the package officially declares on PyPI

    https://imbalanced-learn.org/

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

  • Official repository A link the package officially declares on PyPI

    https://github.com/scikit-learn-contrib/imbalanced-learn

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

  • Official licence file Checked directly

    https://github.com/scikit-learn-contrib/imbalanced-learn/blob/master/LICENSE

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

History of verified versions

VersionRelease dateChecked on
0.14.27 June 202621 November 2026

Page information last reviewed: 21 November 2026. The description was written originally for the encyclopedia and is not copied from the official websites.

Report information that needs updating