Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Scikit learn contrib Imbalanced learn Python Scikit learn

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, Imbalanced_Classification
Last Updated 2026-02-09 03:00 GMT

Overview

Python 3.10+ environment with scikit-learn, NumPy, SciPy, and joblib for imbalanced classification tasks.

Description

This environment provides the core runtime for imbalanced-learn. It is a CPU-based Python environment built on the scikit-learn ecosystem. The library extends scikit-learn's estimator API with resampling transformers (over-sampling, under-sampling, combined), ensemble classifiers with built-in balancing, imbalanced-aware metrics, and a sampler-aware Pipeline. All core functionality runs on CPU and does not require GPU acceleration. An optional pandas dependency enables DataFrame-aware operations.

Usage

Use this environment for all core imbalanced-learn functionality: SMOTE variants, under-sampling algorithms, ensemble classifiers (BalancedRandomForest, BalancedBagging, EasyEnsemble, RUSBoost), imbalanced metrics (geometric mean, IBA, sensitivity/specificity), the sampler-aware Pipeline, and dataset utilities. This environment is the mandatory prerequisite for 18 of 19 Implementation pages.

System Requirements

Category Requirement Notes
OS Any (OS Independent) Linux, macOS, Windows all supported
Hardware CPU No GPU required; all computation is CPU-based
Disk Minimal Only package installation space needed
Platforms (pixi) linux-64, osx-arm64, osx-64, win-64 All major platforms via conda-forge

Dependencies

System Packages

No system-level packages required beyond a Python interpreter.

Python Packages (Core)

  • `python` >= 3.10 (supports 3.10, 3.11, 3.12, 3.13, 3.14)
  • `numpy` >= 1.25.2, < 3
  • `scipy` >= 1.11.4, < 2
  • `scikit-learn` >= 1.4.2, < 2
  • `sklearn-compat` >= 0.1.5, < 0.2
  • `joblib` >= 1.2.0, < 2
  • `threadpoolctl` >= 2.0.0, < 4

Python Packages (Optional)

  • `pandas` >= 2.0.3, < 3 (for DataFrame-aware resampling and column name consistency)

Credentials

No credentials or environment variables are required for core functionality.

Quick Install

# Install imbalanced-learn with all core dependencies
pip install imbalanced-learn

# With optional pandas support
pip install imbalanced-learn pandas>=2.0.3

Code Evidence

Python version constraint from `pyproject.toml:27`:

requires-python = ">=3.10"

Core dependencies from `pyproject.toml:28-35`:

dependencies = [
   "numpy>=1.25.2,<3",
   "scipy>=1.11.4,<2",
   "scikit-learn>=1.4.2,<2",
   "sklearn-compat>=0.1.5,<0.2",
   "joblib>=1.2.0,<2",
   "threadpoolctl>=2.0.0,<4",
]

NumPy 2.0 compatibility handling from `conftest.py:14-17`:

# use legacy numpy print options to avoid failures due to NumPy 2.+ scalar
# representation
if parse_version(np.__version__) > parse_version("2.0.0"):
    np.set_printoptions(legacy="1.25")

Scikit-learn version-specific feature gating from `imblearn/ensemble/_easy_ensemble.py:154`:

if sklearn_version >= parse_version("1.4"):
    # use newer parameter constraints API

Dependency version display from `imblearn/utils/_show_versions.py:21-33`:

deps = [
    "imbalanced-learn", "pip", "setuptools",
    "numpy", "scipy", "scikit-learn",
    "Cython", "pandas", "keras", "tensorflow", "joblib",
]

Common Errors

Error Message Cause Solution
`ImportError: No module named 'imblearn'` Package not installed `pip install imbalanced-learn`
`ImportError: No module named 'sklearn_compat'` sklearn-compat missing or wrong version `pip install sklearn-compat>=0.1.5`
`ValueError: The target 'y' needs to have more than 1 class` Single-class dataset passed to sampler Ensure target variable has at least 2 classes
Pandas `SettingWithCopyWarning` during resampling Using old pandas version Upgrade to `pandas>=2.0.3`

Compatibility Notes

  • NumPy 2.0+: The library handles NumPy 2.0 scalar representation changes via legacy print options in test configuration. Core functionality works with both NumPy 1.x and 2.x.
  • scikit-learn versions: The library adapts to different scikit-learn versions (1.4, 1.5, 1.6) using `sklearn_version` checks. Features like `transform_input` in Pipeline are only available with sklearn >= 1.4.
  • pandas (optional): When installed, enables DataFrame-aware resampling that preserves column names and dtypes. When absent, all operations work on NumPy arrays.
  • Windows: Fully supported for core functionality. Keras/TensorFlow integration is not available on Windows.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment