XGBoosting Home | About | Contact | Examples

Check XGBoost Version

When working with XGBoost, it’s important to know which version you have installed.

Different versions may have different features, bug fixes, or compatibility requirements.

Checking your XGBoost version is straightforward in Python.

import xgboost

print(xgboost.__version__)

Example output (your output may differ):

2.0.3

Here’s what’s happening:

  1. We import the xgboost module.
  2. We use the __version__ attribute of the xgboost module, which holds the installed version as a string.
  3. Printing xgboost.__version__ gives us the version number in the format major.minor.patch.

The version string follows the semantic versioning convention:

Knowing your XGBoost version is useful when:

To compare versions, you can split the version string and compare the individual parts as integers. For example:

import xgboost

required_version = "2.0.0"
current_version = xgboost.__version__

required_parts = [int(x) for x in required_version.split(".")]
current_parts = [int(x) for x in current_version.split(".")]

if current_parts >= required_parts:
    print(f"XGBoost version {current_version} meets the minimum requirement of {required_version}")
else:
    print(f"XGBoost version {current_version} does not meet the minimum requirement of {required_version}")

This script compares the current version with a minimum required version, which is useful when running code that depends on specific XGBoost features or bug fixes.



See Also