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:
- We import the
xgboost
module. - We use the
__version__
attribute of thexgboost
module, which holds the installed version as a string. - Printing
xgboost.__version__
gives us the version number in the formatmajor.minor.patch
.
The version string follows the semantic versioning convention:
- The
major
version indicates significant changes that may break backward compatibility. - The
minor
version indicates new features or improvements that are backward compatible. - The
patch
version indicates bug fixes or minor changes.
Knowing your XGBoost version is useful when:
- You’re following a tutorial or example code that requires a specific version.
- You’re working with other libraries that have compatibility requirements.
- You’re reporting a bug or seeking help on forums or issue trackers.
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.