XGBoosting Home | About | Contact | Examples

Check XGBoost Modules Programmatically

When working with XGBoost in Python, it’s helpful to know which modules are available within the package.

This knowledge can assist you in navigating the API, finding relevant functions, and understanding the library’s capabilities. You can easily get a list of available XGBoost modules programmatically.

import xgboost

print(xgboost.__all__)

Example output (your output may differ):

['DMatrix', 'DeviceQuantileDMatrix', 'QuantileDMatrix', 'Booster', 'DataIter', 'train', 'cv', 'RabitTracker', 'build_info', 'plot_importance', 'plot_tree', 'to_graphviz', 'set_config', 'get_config', 'config_context', 'XGBModel', 'XGBClassifier', 'XGBRegressor', 'XGBRanker', 'XGBRFClassifier', 'XGBRFRegressor', 'dask', 'collective']

We can create a more human readable list that is sported as follows:

import xgboost

for item in sorted(xgboost.__all__):
    print(item)

Example output (your output may differ):

Booster
DMatrix
DataIter
DeviceQuantileDMatrix
QuantileDMatrix
RabitTracker
XGBClassifier
XGBModel
XGBRFClassifier
XGBRFRegressor
XGBRanker
XGBRegressor
build_info
collective
config_context
cv
dask
get_config
plot_importance
plot_tree
set_config
to_graphviz
train

Here’s what’s happening:

  1. We import the xgboost module.
  2. We use the __all__ attribute of the xgboost module, which holds a list of the names of all the modules available in the package.
  3. Printing xgboost.__all__ gives us this list of names available in this module.

You can use this list to explore the XGBoost documentation more efficiently, focusing on the modules relevant to your task.

Knowing which modules are available can help you:

A related approach is to use the Python help system with the modules command.

This shows the layout of the installed modules that have xgboost in their name.

For example:

help('modules xgboost')

Example output (your output may differ):

Here is a list of modules whose name or summary contains 'xgboost'.
If there are any, enter a module name to get more help.

xgboost - XGBoost: eXtreme Gradient Boosting library.
xgboost._typing - Shared typing definition.
xgboost.callback - Callback library containing training routines.  See :doc:`Callback Functions
xgboost.collective - XGBoost collective communication related API.
xgboost.compat - For compatibility and optional dependencies.
xgboost.config - Global configuration for XGBoost
xgboost.core - Core XGBoost Library.
xgboost.dask - Dask extensions for distributed training
xgboost.data - Data dispatching for DMatrix.
xgboost.federated - XGBoost Federated Learning related API.
xgboost.libpath - Find the path to xgboost dynamic library files.
xgboost.plotting - Plotting Library.
xgboost.rabit - Compatibility shim for xgboost.rabit; to be removed in 2.0
xgboost.sklearn - Scikit-Learn Wrapper interface for XGBoost.
xgboost.spark - PySpark XGBoost integration interface
xgboost.testing - Utilities for defining Python tests. The module is private and subject to frequent
xgboost.tracker - This script is a variant of dmlc-core/dmlc_tracker/tracker.py,
xgboost.training - Training Library containing training routines.


See Also