imbalance-xgboost
XGBoost for label-imbalanced data: XGBoost with weighted and focal loss functions
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-xgboostuv
uv add imbalance-xgboostpoetry
poetry add imbalance-xgboostInstalling 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
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
imbalanced-learnProvides re-sampling techniques to address…
permissive · top 5,000 on PyPI
xgboost-cpuXGBoost CPU-only gradient boosting library for…
permissive · top 15,000 on PyPI
imblearnThis package is a deprecated stub that…
unclear · top 5,000 on PyPI
xgboostXGBoost is a gradient boosting library that…
permissive · top 1,000 on PyPI
dtreevizdtreeviz renders decision trees from…
permissive · top 15,000 on PyPI
catboostCatBoost is a gradient boosting library that…
permissive · top 5,000 on PyPI
pytorch-metric-learningProvides metric learning loss functions,…
permissive · top 5,000 on PyPI
sklearn-crfsuitesklearn-crfsuite wraps CRFsuite (Conditional…
permissive · top 15,000 on PyPI
xgboost-rayDistributes XGBoost training and inference…
permissive · top 15,000 on PyPI
geomlossComputes geometric loss functions for comparing…
permissive · top 15,000 on PyPI