### C/C++ Application Tutorial Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md A tutorial for using the C API in a C/C++ application. This guide covers the necessary steps and code examples for integrating XGBoost into native C/C++ projects. ```c // Example C/C++ code snippet using XGBoost C API #include int main() { // Initialize XGBoost // Load data // Train model // Make predictions // Cleanup return 0; } ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/dmlc/xgboost/blob/master/demo/c-api/CMakeLists.txt Specifies the minimum required CMake version and defines the project name for the C API examples. ```cmake cmake_minimum_required(VERSION 3.18) project(xgboost-c-examples) ``` -------------------------------- ### Install and Install Pre-commit Hooks Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/coding_guide.md Installs the pre-commit package and enables its hooks for the local repository. This is the first step to running local formatting and sanity checks. ```bash python -m pip install pre-commit pre-commit install ``` -------------------------------- ### Run CPU Container Example Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/ci.md Example of running a command within a CPU-enabled XGBoost Docker container. ```bash # Run without GPU python3 ops/docker_run.py \ --image-uri 492475357299.dkr.ecr.us-west-2.amazonaws.com/xgb-ci.cpu:main \ -- bash ops/pipeline/build-cpu-impl.sh cpu ``` -------------------------------- ### Install Ray Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/ray.md Install the Ray framework via pip. ```bash pip install ray ``` -------------------------------- ### Install Documentation Requirements Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/docs.md Install the necessary Python packages for building documentation using pip from requirements.txt. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install using system-provided library Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Configures the installation to use an existing system-wide shared library instead of building a new one. ```bash cd python-package pip install . --config-settings use_system_libxgboost=True ``` -------------------------------- ### Install XGBoost with GPU Support (R Nightly) Source: https://github.com/dmlc/xgboost/blob/master/doc/install.md Install an experimental GPU-enabled XGBoost binary for R from nightly builds. Download the appropriate .tar.gz file for your OS and install using R CMD INSTALL. ```bash # Install dependencies R -q -e "install.packages(c('data.table', 'jsonlite', 'remotes'))" # Install XGBoost R CMD INSTALL ./xgboost_r_gpu_linux.tar.gz ``` -------------------------------- ### Install XGBoost-Ray Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/ray.md Install the XGBoost-Ray library via pip. ```bash pip install xgboost_ray ``` -------------------------------- ### Install XGBoost from Binary Wheel Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/python_packaging.md Installs the pre-compiled wheel, which skips the compilation step and completes quickly. ```console $ pip install xgboost-2.0.0-py3-none-linux_x86_64.whl # Completes quickly ``` -------------------------------- ### Docker Build Arguments Example Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/ci.md Example of build arguments passed to the Docker build command, corresponding to ARG instructions in the Dockerfile. ```default --build-arg CUDA_VERSION_ARG=12.4.1 --build-arg NCCL_VERSION_ARG=2.23.4-1 \ --build-arg RAPIDS_VERSION_ARG=24.10 ``` -------------------------------- ### Adding Example Subdirectories Source: https://github.com/dmlc/xgboost/blob/master/demo/c-api/CMakeLists.txt Includes subdirectories for different categories of C API examples: basic, external-memory, and inference. ```cmake add_subdirectory(basic) add_subdirectory(external-memory) add_subdirectory(inference) ``` -------------------------------- ### Install R Package from Source (Linux/Mac) Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Install the R package after obtaining the source code. Ensure git and a C++11 compliant compiler are installed. ```bash cd R-package R CMD INSTALL . ``` -------------------------------- ### Install NVFlare Source: https://github.com/dmlc/xgboost/blob/master/demo/nvflare/vertical/README.md Install the NVFlare library using pip. This is a prerequisite for running federated learning tasks. ```shell pip install nvflare ``` -------------------------------- ### Install XGBoost Libraries Source: https://github.com/dmlc/xgboost/blob/master/CMakeLists.txt Installs the XGBoost libraries. If XGBoost is built as a static library, 'objxgboost' is also installed to prevent export set errors. ```cmake if(BUILD_STATIC_LIB) set(INSTALL_TARGETS xgboost objxgboost dmlc) else() set(INSTALL_TARGETS xgboost) endif() install(TARGETS ${INSTALL_TARGETS} EXPORT XGBoostTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS}) ``` -------------------------------- ### Run GPU Container Example Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/ci.md Example of running a command within an NVIDIA GPU-enabled XGBoost Docker container. ```bash # Run with NVIDIA GPU python3 ops/docker_run.py \ --image-uri 492475357299.dkr.ecr.us-west-2.amazonaws.com/xgb-ci.gpu:main \ --use-gpus \ -- bash ops/pipeline/test-python-wheel.sh gpu ``` -------------------------------- ### Install Python package with pre-built C++ library Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Reuses an existing shared library in the lib/ directory to speed up the installation process. ```console $ cd python-package/ $ pip install . # Will re-use lib/libxgboost.so ``` -------------------------------- ### Build and Install XGBoost4J with Maven (Skip Tests) Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Build and install the XGBoost4J package using Maven, skipping tests. Ensure JAVA_HOME is set. ```bash mvn -DskipTests=true package ``` -------------------------------- ### Install XGBoost4J to Local Maven Repository Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Install XGBoost4J artifacts to the local Maven repository. Ensure JAVA_HOME is set. ```bash mvn install ``` -------------------------------- ### Install XGBoost from Source Distribution Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/python_packaging.md Installs the package from an sdist, triggering the compilation of C++ code into the shared library. ```console $ pip install -v xgboost-2.0.0.tar.gz # Add -v to show build progress ``` -------------------------------- ### Start NVFlare Federated Server Source: https://github.com/dmlc/xgboost/blob/master/demo/nvflare/vertical/README.md Launch the NVFlare federated server. This command starts the central server that coordinates the federated learning process. ```shell /tmp/nvflare/poc/server/startup/start.sh ``` -------------------------------- ### Install Kubeflow Python SDK Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/kubernetes.md Install the Kubeflow Python SDK using pip. This is optional and primarily used for programmatic job submission. ```bash pip install kubeflow ``` -------------------------------- ### Install XGBoost from PyPI Source: https://github.com/dmlc/xgboost/blob/master/python-package/README.dft.rst Use this command to install the latest stable version of the XGBoost Python package. Ensure pip is available in your environment. ```bash pip install xgboost ``` -------------------------------- ### Install XGBoost4J to Local Maven Repository (Skip Tests) Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Install XGBoost4J artifacts to the local Maven repository, skipping tests. Ensure JAVA_HOME is set. ```bash mvn -DskipTests install ``` -------------------------------- ### Install XGBoost Headers Source: https://github.com/dmlc/xgboost/blob/master/CMakeLists.txt Installs all XGBoost C++ headers to the system's include directory. Note that these headers do not currently form a stable API. ```cmake install(DIRECTORY ${xgboost_SOURCE_DIR}/include/xgboost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ``` -------------------------------- ### Install XGBoost with Pip (CPU-only) Source: https://github.com/dmlc/xgboost/blob/master/doc/install.md Use this command to install the CPU-only variant of XGBoost, which has a smaller disk footprint and excludes GPU algorithms and federated learning. ```bash pip install xgboost-cpu ``` -------------------------------- ### Dtreeviz Showcase Example Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md An example showcasing integration with dtreeviz, a third-party software for visualizing decision trees. This demonstrates how XGBoost models can be visualized effectively. ```python import xgboost as xgb from dtreeviz.model import dtreeviz # Assuming 'model' is a trained XGBoost model # and 'X_train', 'y_train' are training data viz = dtreeviz(model, X_train, y_train, target_name='target', feature_names=feature_names) viz.view() ``` -------------------------------- ### Example JSON Configuration Structure Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/saving_model.md An example of the JSON structure representing XGBoost's internal configuration. Note that actual output may vary and can be very long. ```javascript { "Learner": { "generic_parameter": { "device": "cuda:0", "gpu_page_size": "0", "n_jobs": "0", "random_state": "0", "seed": "0", "seed_per_iteration": "0" }, "gradient_booster": { "gbtree_train_param": { "num_parallel_tree": "1", "process_type": "default", "tree_method": "hist", "updater": "grow_gpu_hist", "updater_seq": "grow_gpu_hist" }, "name": "gbtree", "updater": { "grow_gpu_hist": { "gpu_hist_train_param": { "debug_synchronize": "0" }, "train_param": { "alpha": "0", "cache_opt": "1", "colsample_bylevel": "1", "colsample_bynode": "1", "colsample_bytree": "1", "default_direction": "learn", "subsample": "1" } } } }, "learner_train_param": { "booster": "gbtree", "disable_default_eval_metric": "0", "objective": "reg:squarederror" }, "metrics": [], "objective": { "name": "reg:squarederror", "reg_loss_param": { "scale_pos_weight": "1" } } }, "version": [1, 0, 0] } ``` -------------------------------- ### Install Python Nightly Build Source: https://github.com/dmlc/xgboost/blob/master/doc/install.md Install a nightly build of XGBoost for Python by providing the URL to the wheel file. This allows access to the latest features and fixes. ```bash pip install ``` -------------------------------- ### Flink API: Distributed Training with Flink Source: https://github.com/dmlc/xgboost/blob/master/jvm-packages/xgboost4j-example/README.md Illustrates distributed training using XGBoost with Apache Flink. This example requires a Flink environment setup. ```Scala package ml.dmlc.xgboost4j.scala.example.flink import org.apache.flink.api.scala._ import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment import ml.dmlc.xgboost4j.flink.XGBoost object DistTrainWithFlink { def main(args: Array[String]): Unit = { val env = StreamExecutionEnvironment.getExecutionEnvironment // Sample data creation (replace with your actual Flink data sources) // For demonstration, creating a small bounded stream val trainingData = env.fromElements( Array(1.0f, 2.0f, 0.0f), Array(2.0f, 3.0f, 0.0f), Array(3.0f, 4.0f, 0.0f), Array(4.0f, 5.0f, 1.0f), Array(5.0f, 6.0f, 1.0f), Array(6.0f, 7.0f, 1.0f) ) // Configure XGBoost parameters val params = Map( "eta" -> "0.1", "max_depth" -> "3", "objective" -> "binary:logistic", "num_round" -> "10" ) // Train XGBoost model using Flink val booster = XGBoost.train(trainingData, params, 1, "label", "features") // You can then use the trained 'booster' for predictions within Flink jobs // For simplicity, we'll just print a confirmation println("XGBoost model training with Flink initiated.") // Note: Flink jobs typically run continuously or until a condition is met. // For this example, we'll execute the environment. // env.execute("XGBoost Flink Training") } } ``` -------------------------------- ### Java API: Basic Walkthrough Source: https://github.com/dmlc/xgboost/blob/master/jvm-packages/xgboost4j-example/README.md Demonstrates the basic usage of XGBoost4J wrappers in Java. No specific setup required beyond standard Java compilation. ```Java package ml.dmlc.xgboost4j.java.example; import ml.dmlc.xgboost4j.java.Booster; import ml.dmlc.xgboost4j.java.DMatrix; import ml.dmlc.xgboost4j.java.XGBoost; import java.util.Arrays; import java.util.stream.Collectors; public class BasicWalkThrough { public static void main(String[] args) throws Exception { // specify the path to the training data String trainUri = "src/main/java/ml/dmlc/xgboost4j/java/example/sample.train.libsvm"; // specify the path to the test data String testUri = "src/main/java/ml/dmlc/xgboost4j/java/example/sample.test.libsvm"; // load the training data DMatrix trainMat = new DMatrix(trainUri); // load the test data DMatrix testMat = new DMatrix(testUri); // specify the training parameters java.util.Map params = new java.util.HashMap() { { put("eta", 1); put("max_depth", 2); put("objective", "binary:logistic"); } }; // specify the number of boosting rounds int rounds = 2; // train the model Booster booster = XGBoost.train(trainMat, params, rounds, null, null, null); // predict the result on the test data float[][] predicts = booster.predict(testMat); // print the predictions System.out.println("predict result:"); for (int i = 0; i < predicts.length; i++) { System.out.println(Arrays.toString(predicts[i])); } // save the model booster.saveModel("model.bst"); // load the model Booster booster2 = XGBoost.loadModel("model.bst"); // predict again with the loaded model predicts = booster2.predict(testMat); System.out.println("predict result with loaded model:"); for (int i = 0; i < predicts.length; i++) { System.out.println(Arrays.toString(predicts[i])); } } } ``` -------------------------------- ### XGBoost Evals Result Example Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_api.md If eval_set is passed to the fit() function, you can call evals_result() to get evaluation results for all passed eval_sets. When eval_metric is also passed to the fit() function, the evals_result will contain the eval_metrics passed to the fit() function. ```python evals_result = { 'validation_0': {'logloss': ['0.604835', '0.531479']}, 'validation_1': {'logloss': ['0.41965', '0.17686']} } ``` -------------------------------- ### Initialize and Start RabitTracker Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_api.md Demonstrates how to initialize a RabitTracker for a specified number of workers and IP address, then start the tracker. It also shows how to use the tracker's worker arguments within a collective communicator context to broadcast a message. ```python from xgboost.tracker import RabitTracker from xgboost import collective as coll tracker = RabitTracker(host_ip="127.0.0.1", n_workers=2) tracker.start() with coll.CommunicatorContext(**tracker.worker_args()): ret = coll.broadcast("msg", 0) assert str(ret) == "msg" ``` -------------------------------- ### Run C++ Google Tests Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/unit_tests.md Instructions for running C++ unit tests using Google Test. Ensure Google Test version 1.8.1 or later is installed. The exact command to run these tests is not provided in this snippet, but the setup is implied. -------------------------------- ### Install XGBoost R-package Source: https://github.com/dmlc/xgboost/blob/master/demo/kaggle-otto/README.MD Use this command to install the XGBoost R-package from the CRAN repository. Windows users may need to install RTools first. ```r install.packages("xgboost", repos = "https://cran.r-project.org") ``` -------------------------------- ### Scala API: Basic Walkthrough Source: https://github.com/dmlc/xgboost/blob/master/jvm-packages/xgboost4j-example/README.md Provides a basic example of using XGBoost4J with the Scala API. Similar to the Java version but idiomatic Scala. ```Scala package ml.dmlc.xgboost4j.scala.example import ml.dmlc.xgboost4j.scala.Booster import ml.dmlc.xgboost4j.scala.DMatrix import ml.dmlc.xgboost4j.scala.XGBoost object BasicWalkThrough { def main(args: Array[String]): Unit = { // specify the path to the training data val trainUri = "src/main/scala/ml/dmlc/xgboost4j/scala/example/sample.train.libsvm" // specify the path to the test data val testUri = "src/main/scala/ml/dmlc/xgboost4j/scala/example/sample.test.libsvm" // load the training data val trainMat = new DMatrix(trainUri) // load the test data val testMat = new DMatrix(testUri) // specify the training parameters val params = Map( "eta" -> 1, "max_depth" -> 2, "objective" -> "binary:logistic" ) // specify the number of boosting rounds val rounds = 2 // train the model val booster = XGBoost.train(trainMat, params, rounds, null, null, null) // predict the result on the test data val predicts = booster.predict(testMat) // print the predictions println("predict result:") predicts.foreach(println) // save the model booster.saveModel("model.bst") // load the model val booster2 = XGBoost.loadModel("model.bst") // predict again with the loaded model val predicts2 = booster2.predict(testMat) println("predict result with loaded model:") predicts2.foreach(println) } } ``` -------------------------------- ### Configure and Install Pkg-config File Source: https://github.com/dmlc/xgboost/blob/master/CMakeLists.txt Conditionally configures and installs the 'xgboost.pc' file if the ADD_PKGCONFIG option is enabled. This file is used by pkg-config to find the installed XGBoost library. ```cmake if(ADD_PKGCONFIG) configure_file(${xgboost_SOURCE_DIR}/cmake/xgboost.pc.in ${xgboost_BINARY_DIR}/xgboost.pc @ONLY) install( FILES ${xgboost_BINARY_DIR}/xgboost.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() ``` -------------------------------- ### XGBRegressor Initialization and Training Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_api.md Demonstrates initializing XGBRegressor with parameters and callbacks, followed by training the model. ```APIDOC ## XGBRegressor Initialization and Training ### Description This snippet shows how to initialize an `XGBRegressor` model with a grid of parameters and custom learning rate callbacks, then train the model on the provided data. ### Code Example ```python for params in parameters_grid: # be sure to (re)initialize the callbacks before each run callbacks = [xgb.callback.LearningRateScheduler(custom_rates)] reg = xgboost.XGBRegressor(**params, callbacks=callbacks) reg.fit(X, y) ``` ### Parameters * **&&kwargs** (*Optional* *[**Any* *]*) – Keyword arguments for XGBoost Booster object. Full documentation of parameters can be found [here](../parameter.md). *NOTE: &&kwargs unsupported by scikit-learn* &&kwargs is unsupported by scikit-learn. We do not guarantee that parameters passed via this argument will interact properly with scikit-learn. *NOTE: Custom objective function* A custom objective function can be provided for the `objective` parameter. In this case, it should have the signature `objective(y_true, y_pred) -> [grad, hess]` or `objective(y_true, y_pred, *, sample_weight) -> [grad, hess]`: * **y_true**: array_like of shape [n_samples] - The target values * **y_pred**: array_like of shape [n_samples] - The predicted values * **sample_weight**: Optional sample weights. * **grad**: array_like of shape [n_samples] - The value of the gradient for each sample point. * **hess**: array_like of shape [n_samples] - The value of the second derivative for each sample point Note that, if the custom objective produces negative values for the Hessian, these will be clipped. If the objective is non-convex, one might also consider using the expected Hessian (Fisher information) instead. ``` -------------------------------- ### Initialize Data for XGBoost Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/intercept.md Setup the training data for the binary classification task. ```py import numpy as np from scipy.special import logit from sklearn.datasets import make_classification import xgboost as xgb X, y = make_classification(random_state=2025) ``` ```r library(xgboost) # Load built-in dataset data(agaricus.train, package = "xgboost") X <- agaricus.train$data y <- agaricus.train$label ``` -------------------------------- ### Force GPU Variant Installation with Conda Source: https://github.com/dmlc/xgboost/blob/master/doc/install.md To force the installation of the GPU variant of XGBoost with Conda on a machine without an NVIDIA GPU, set the CONDA_OVERRIDE_CUDA environment variable before installing. ```bash export CONDA_OVERRIDE_CUDA="12.8" conda install -c conda-forge py-xgboost=*=cuda* ``` -------------------------------- ### Dask Distributed Example (Copy-Pastable) Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md Makes the Dask distributed example copy-pastable. This ensures that users can easily copy and run the provided Dask example code without modification. ```python from dask.distributed import Client, LocalCluster import xgboost as xgb # Setup Dask cluster cluster = LocalCluster() client = Client(cluster) # Example XGBoost training with Dask dmatrix = xgb.DaskDMatrix(X, y) model = xgb.dask.train(client, params, dmatrix) client.close() cluster.close() ``` -------------------------------- ### Build XGBoost Documentation Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/docs.md Build the HTML documentation for XGBoost locally using the make html command. ```bash make html ``` -------------------------------- ### Install XGBoost on Mac OSX Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md Two commands are sufficient to install XGBoost on Mac OSX, enabling multi-core CPU utilization. Alternatively, XGBoost can be installed directly via Homebrew. ```bash brew install libomp pip install xgboost ``` ```bash brew install xgboost ``` -------------------------------- ### Install XGBoost on Mac OSX Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md Install XGBoost on Mac OSX using Homebrew and Pip. This method utilizes all CPU cores and benefits from pre-compiled binary wheels for faster installation. ```bash brew install libomp ``` ```bash pip install xgboost ``` -------------------------------- ### Verify XGBoost Installation Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_intro.md Run this Python code to verify your XGBoost installation. ```python import xgboost as xgb ``` -------------------------------- ### Install NCCL for XGBoost Pip Installation Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/dask.md Install the NVIDIA Collective Communications Library (NCCL) using pip if you encounter 'Failed to load nccl' errors. Ensure the CUDA version is compatible. ```sh pip install nvidia-nccl-cu12 # (or with any compatible CUDA version) ``` -------------------------------- ### Install XGBoost in Conda Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/c_api_tutorial.md Commands to clone the repository, build, and install XGBoost into a Conda environment. ```bash # clone the XGBoost repository & its submodules git clone --recursive https://github.com/dmlc/xgboost cd xgboost # Activate the Conda environment, into which we'll install XGBoost conda activate [env_name] # Build the compiled version of XGBoost inside the build folder cmake -B build -S . -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX # install XGBoost in your conda environment (usually under [your home directory]/miniconda3) cmake --build build --target install ``` -------------------------------- ### Perform an editable installation Source: https://github.com/dmlc/xgboost/blob/master/doc/build.md Creates a symbolic link to the source code, allowing immediate reflection of changes in the Python interpreter. ```bash # Build shared library libxgboost.so cmake -B build -S . -GNinja cd build && ninja # Install as editable installation cd ../python-package pip install -e . ``` -------------------------------- ### Start NVFlare Nodes Source: https://github.com/dmlc/xgboost/blob/master/demo/nvflare/horizontal/README.md Commands to initialize the federated server and worker nodes. ```shell /tmp/nvflare/poc/server/startup/start.sh ``` ```shell /tmp/nvflare/poc/site-1/startup/start.sh ``` ```shell /tmp/nvflare/poc/site-2/startup/start.sh ``` -------------------------------- ### Install Graphviz with Conda Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/docs.md Install the Graphviz package using Conda, which may be required for certain documentation features. ```bash conda install graphviz --yes ``` -------------------------------- ### explainParams() Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_api.md Returns the documentation of all params with their optionally default values and user-supplied values. ```APIDOC ## explainParams() ### Description Returns the documentation of all params with their optionally default values and user-supplied values. ### Return type str ``` -------------------------------- ### XGBoost CI Container Definition Example Source: https://github.com/dmlc/xgboost/blob/master/doc/contrib/ci.md Example YAML configuration for a CI container, specifying the container definition, build arguments like CUDA and NCCL versions. ```yaml xgb-ci.gpu: container_def: gpu build_args: CUDA_VERSION_ARG: "12.4.1" NCCL_VERSION_ARG: "2.23.4-1" RAPIDS_VERSION_ARG: "24.10" ``` -------------------------------- ### Start NVFlare Admin CLI Source: https://github.com/dmlc/xgboost/blob/master/demo/nvflare/vertical/README.md Launch the NVFlare admin command-line interface. This tool is used to submit jobs and manage the federated learning environment. ```shell /tmp/nvflare/poc/admin/startup/fl_admin.sh ``` -------------------------------- ### Install XGBoost R Package Source: https://github.com/dmlc/xgboost/blob/master/R-package/README.md Install the stable version of the XGBoost R package from CRAN. This is the recommended method for most users. ```r install.packages('xgboost') ``` -------------------------------- ### Python Example for Learning to Rank with XGBRanker Source: https://github.com/dmlc/xgboost/blob/master/NEWS.md Demonstrates how to use the XGBRanker class for learning to rank tasks within the scikit-learn interface. This example is located in the demo directory. ```Python import xgboost as xgb from sklearn.model_selection import train_test_split # Load data (replace with your actual data loading) # Assuming X contains features and y contains relevance scores # X = ... # y = ... # For demonstration, create dummy data from sklearn.datasets import make_classification X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, n_redundant=0, random_state=42) # Group IDs are required for learning to rank # Assuming each group has a unique ID, here we create dummy group IDs group_ids = np.random.randint(0, 10, size=1000) # Split data X_train, X_test, y_train, y_test, group_train, group_test = train_test_split(X, y, group_ids, test_size=0.2, random_state=42) # Initialize XGBRanker ranker = xgb.XGBRanker(objective='rank:pairwise', # or 'rank:ndcg', 'rank:map' eval_metric='ndcg', n_estimators=100, learning_rate=0.1, random_state=42) # Train the model # Note: XGBRanker expects group information during fit ranker.fit(X_train, y_train, group=group_train, eval_set=[(X_test, y_test)], eval_group=[group_test], early_stopping_rounds=10) # Predict preds = ranker.predict(X_test) print("XGBRanker model trained and predictions made.") ``` -------------------------------- ### Configure Hyperparameter Optimization with Ray Tune Source: https://github.com/dmlc/xgboost/blob/master/doc/tutorials/ray.md Demonstrates setting up a training function, defining a search space, and executing a tune run with XGBoost-Ray. ```python from xgboost_ray import RayDMatrix, RayParams, train from sklearn.datasets import load_breast_cancer num_actors = 4 num_cpus_per_actor = 1 ray_params = RayParams( num_actors=num_actors, cpus_per_actor=num_cpus_per_actor) def train_model(config): train_x, train_y = load_breast_cancer(return_X_y=True) train_set = RayDMatrix(train_x, train_y) evals_result = {} bst = train( params=config, dtrain=train_set, evals_result=evals_result, evals=[(train_set, "train")], verbose_eval=False, ray_params=ray_params) bst.save_model("model.xgb") from ray import tune # Specify the hyperparameter search space. config = { "tree_method": "approx", "objective": "binary:logistic", "eval_metric": ["logloss", "error"], "eta": tune.loguniform(1e-4, 1e-1), "subsample": tune.uniform(0.5, 1.0), "max_depth": tune.randint(1, 9) } ``` -------------------------------- ### Create Quantilized DMatrix for Training and Testing Source: https://github.com/dmlc/xgboost/blob/master/doc/python/python_api.md Demonstrates how to create a QuantileDMatrix for training data and a reference QuantileDMatrix for test data. The reference is crucial for applying consistent quantiles to validation/test sets. ```python from sklearn.datasets import make_regression from sklearn.model_selection import train_test_split X, y = make_regression() X_train, X_test, y_train, y_test = train_test_split(X, y) Xy_train = xgb.QuantileDMatrix(X_train, y_train) # It's necessary to have the training DMatrix as a reference for valid # quantiles. Xy_test = xgb.QuantileDMatrix(X_test, y_test, ref=Xy_train) ``` -------------------------------- ### Start NVFlare Worker 1 Source: https://github.com/dmlc/xgboost/blob/master/demo/nvflare/vertical/README.md Start the first worker node for the federated learning job. This command should be run in a separate terminal. ```shell /tmp/nvflare/poc/site-1/startup/start.sh ```