{"id":27873,"library":"imbalance-xgboost","title":"Imbalance-XGBoost","description":"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.","status":"maintenance","version":"0.8.1","language":"python","source_language":"en","source_url":"https://github.com/jhwjhw0123/Imbalance-XGBoost","tags":["xgboost","imbalanced-data","focal-loss","weighted-loss","machine-learning"],"install":[{"cmd":"pip install imbalance-xgboost","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency; must be >=1.1.1","package":"xgboost","optional":false},{"reason":"Array operations","package":"numpy","optional":false},{"reason":"Data handling","package":"pandas","optional":false},{"reason":"Train/test split and metrics","package":"scikit-learn","optional":false}],"imports":[{"note":"Direct import from package is correct; submodule not exposed.","wrong":"from imxgboost.imxgbclassifier import XGBClassifier","symbol":"XGBClassifier","correct":"from imxgboost import XGBClassifier"},{"note":"Regressor is available at top level.","wrong":"from imxgboost.weight import XGBRegressor","symbol":"XGBRegressor","correct":"from imxgboost import XGBRegressor"},{"note":"Focal loss is built into the classifier via parameter; no separate class.","wrong":"from imxgboost.focal_loss import FocalLoss","symbol":"FocalLoss","correct":"from imxgboost import XGBClassifier; then set objective='focal'"}],"quickstart":{"code":"import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom imxgboost import XGBClassifier\n\n# Load data\nfrom sklearn.datasets import make_classification\nX, y = make_classification(n_classes=2, weights=[0.9, 0.1], n_samples=1000, random_state=42)\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Model with focal loss\nmodel = XGBClassifier(objective='focal', focal_gamma=2.0, scale_pos_weight=None)\nmodel.fit(X_train, y_train)\npreds = model.predict(X_test)\nprint('Accuracy:', (preds == y_test).mean())\n\n# Weighted loss (sample weights)\nweights = [10 if yi == 0 else 1 for yi in y_train]\nmodel2 = XGBClassifier(objective='weighted')\nmodel2.fit(X_train, y_train, sample_weight=weights)\nprint('Weighted model accuracy:', (model2.predict(X_test) == y_test).mean())","lang":"python","description":"Train XGBoost with focal loss and weighted loss on imbalanced data."},"warnings":[{"fix":"Upgrade XGBoost: pip install --upgrade xgboost>=1.1.1","message":"Requires XGBoost >=1.1.1. Older XGBoost versions will cause import errors or silent failures.","severity":"breaking","affected_versions":"imbalance-xgboost >=0.8.0"},{"fix":"Use `from imxgboost import ...` (no underscore).","message":"The package is often imported as `imxgboost` (not `imbalance_xgboost`). Using the wrong module name leads to ModuleNotFoundError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use exactly 'focal' or 'weighted' for objective.","message":"Focal 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.","severity":"gotcha","affected_versions":"all"},{"fix":"For active development, use XGBoost's native `scale_pos_weight` or implement custom focal loss.","message":"The package is in maintenance mode; no new features expected. Consider using XGBoost native weighted loss or focal loss via custom objective as alternatives.","severity":"deprecated","affected_versions":"0.8.1"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Ensure you have installed imbalance-xgboost and use `import imxgboost` correctly.","cause":"Common typo: package is installed as 'imbalance-xgboost' but imported as 'imxgboost' (no underscore).","error":"ModuleNotFoundError: No module named 'imxgboost'"},{"fix":"Use `from imxgboost import XGBClassifier`.","cause":"Attempting to import from wrong submodule or using outdated import pattern.","error":"AttributeError: module 'imxgboost' has no attribute 'XGBClassifier'"},{"fix":"Install XGBoost with GPU support: `pip install xgboost-gpu` or set `tree_method='hist'`.","cause":"Trying to use GPU with a CPU-only XGBoost installation or mismatched XGBoost version.","error":"xgboost.core.XGBoostError: No available GPU?"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}