skillfed

imbalance-xgboost

XGBoost for label-imbalanced data: XGBoost with weighted and focal loss functions

imbalance-xgboost v0.8.1 151.2K downloads/30d#10,940 on PyPI341
Permissive license MIT DORMANT released

What it is and what it does

Imbalance-XGBoost is a wrapper around XGBoost that implements weighted and focal loss functions for binary classification on imbalanced datasets. The package handles the mathematical complexity of computing first and second-order gradients required by XGBoost's custom loss interface, so you can use these loss functions without deriving the math yourself. It exposes the loss choice via a `special_objective` parameter and allows tuning of the imbalance factor (α) and focal parameter (γ) at initialization.

The wrapper is designed to be compatible with scikit-learn's API, so you can use it with GridSearchCV and other sklearn utilities for hyperparameter tuning. It provides multiple prediction methods (raw logits, sigmoid probabilities, binary class labels, and two-class probability distributions) and includes evaluation functions for metrics like accuracy, precision, recall, F1, and confusion matrix components. However, the package has not been actively maintained since February 2021, and its compatibility with modern Python and XGBoost versions is untested.

Use it for:

  • Tuning focal loss hyperparameters (γ) on imbalanced binary datasets using GridSearchCV.
  • Comparing weighted loss (α) versus focal loss on the same imbalanced classification problem.
  • Integrating custom loss functions into scikit-learn pipelines and cross-validation workflows.
  • Evaluating classification performance on imbalanced data using confusion matrix metrics.
  • Training boosted models when one class is significantly underrepresented in the training set.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Wraps XGBoost with weighted and focal loss functions to handle binary classification on imbalanced datasets, computing the required gradients automatically.

Yes, if you need focal or weighted loss for XGBoost on imbalanced binary classification and are willing to test compatibility with your XGBoost version. The package has low install friction and permissive licensing. However, dormancy since 2021 means no active maintenance, so verify it works with your current environment before relying on it in production.

Install

imbalance-xgboost on PyPI

pip

pip install imbalance-xgboost

uv

uv add imbalance-xgboost

poetry

poetry add imbalance-xgboost

Installing imbalance-xgboost

Before you install

Low friction installation with three core dependencies (numpy, scikit-learn, xgboost). Package is dormant—last release was in February 2021, so expect no active maintenance or updates.

License in practice

MIT license is permissive, allowing free use, modification, and distribution with minimal restrictions, making it safe for most projects.

Quickstart

pip install imbalance-xgboost
from imbalance_xgboost import imbalance_xgboost
model = imbalance_xgboost(special_objective='focal')
model.fit(X_train, y_train)
predictions = model.predict_sigmoid(X_test)

Requires xgboost >= 1.1.1 as of version 0.8.1; package was tested on Python 3.5 and 3.6 with incomplete testing on 3.7 and 3.8.

Verify before relying

  • Compatibility with Python versions beyond 3.8 and current XGBoost releases (last tested in early 2021).
  • Whether early stopping feature (added in 0.8.1) works reliably with recent XGBoost versions.
  • Real-world performance gains compared to XGBoost's native scale_pos_weight or other imbalance handling methods.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 3 — numpy, scikit-learn, xgboost
Maintenance dormant — 2,013 days since the last release
Last repo commit
First released
Downloads 151,179/month — #10,940 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: imbalance_xgboost-0.8.1-py3-none-any.whl

Intended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6

Tags

xgboost imbalanced datafocal loss binary classificationweighted loss xgboostclass imbalance handlingxgboost custom loss functionimbalanced dataset classifierxgboost label imbalance
imbalanced-classificationgradient-boostingsklearn-compatible

More Artificial Intelligence packages