Registry / ai-ml / imbalance-xgboost

imbalance-xgboost

JSON →
library0.8.1pypypiunverified

Imbalance-XGBoost is a Python package that extends XGBoost with weighted and focal loss functions for label-imbalanced data. Current version 0.8.1 requires XGBoost >=1.1.1. Release cadence is sporadic; last release was June 2022.

pip install imbalance-xgboost
INSTALL
IMPORT
SIG · IMBALANCE-XGBOOST
I
imbalance-xgboost
ai-mlpythonv0.8.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

XGBClassifier
from imxgboost import XGBClassifier
from imxgboost import XGBClassifier

Train XGBoost with focal loss and weighted loss on imbalanced data.

import pandas as pd from sklearn.model_selection import train_test_split from imxgboost import XGBClassifier # Load data from sklearn.datasets import make_classification X, y = make_classification(n_classes=2, weights=[0.9, 0.1], n_samples=1000, random_state=42) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Model with focal loss model = XGBClassifier(objective='focal', focal_gamma=2.0, scale_pos_weight=None) model.fit(X_train, y_train) preds = model.predict(X_test) print('Accuracy:', (preds == y_test).mean()) # Weighted loss (sample weights) weights = [10 if yi == 0 else 1 for yi in y_train] model2 = XGBClassifier(objective='weighted') model2.fit(X_train, y_train, sample_weight=weights) print('Weighted model accuracy:', (model2.predict(X_test) == y_test).mean())
Debug
Known issues
breakingRequires XGBoost >=1.1.1. Older XGBoost versions will cause import errors or silent failures.
fix
Upgrade XGBoost: pip install --upgrade xgboost>=1.1.1
affects: imbalance-xgboost >=0.8.0
gotchaThe package is often imported as `imxgboost` (not `imbalance_xgboost`). Using the wrong module name leads to ModuleNotFoundError.
fix
Use `from imxgboost import ...` (no underscore).
affects: all
gotchaFocal loss and weighted loss parameters are passed as strings (e.g., objective='focal'). Misspelling or case mismatch (e.g., 'Focal') will silently fall back to default objective.
fix
Use exactly 'focal' or 'weighted' for objective.
affects: all
deprecatedThe package is in maintenance mode; no new features expected. Consider using XGBoost native weighted loss or focal loss via custom objective as alternatives.
fix
For active development, use XGBoost's native `scale_pos_weight` or implement custom focal loss.
affects: 0.8.1
Upgrade
Version history
0.8.1latest on PyPI · released Feb 8, 2021
Audit
Dependencies
xgboostrequiredCore dependency; must be >=1.1.1
numpyrequiredArray operations
pandasrequiredData handling
scikit-learnrequiredTrain/test split and metrics
Agent activity
6 hits · last 30 days
node
6
Resources
imbalance-xgboost — pip install imbalance-xgboost · libregistry