Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

What Is XGBoost? Install, Run and Read It for Research

What XGBoost is, how to install it from the official docs, a runnable train-predict-save sequence, and how to report it in research.

Written and maintained by CASRAI Editorial Board

Last updated

XGBoost is an open-source, supervised machine-learning library that builds gradient boosted trees: an ensemble of decision trees (CARTs) added one at a time, each correcting the previous ones. Its official tutorial describes it as the same family of tree ensembles as a random forest, differing in how the trees are trained: “random forests and boosted trees are really the same models; the difference arises from how we train them.” This guide covers what it does for a research project, how to install it from the official documentation, a runnable train-predict-save sequence, how to read the objective that the documented parameters control, and how to report it. Details were checked against the official documentation on 2026-10-29.

What is XGBoost used for in research?

XGBoost fits supervised models: you give it a table of input features and a label, and it learns a function that predicts the label. A researcher reaches for it when a regression or classification model on tabular data is needed and a single linear model is not enough. For the broader picture of how such models fit into a study, see what machine learning is and where it goes wrong in research.

The library was introduced by Tianqi Chen and Carlos Guestrin in “XGBoost: A Scalable Tree Boosting System” (arXiv:1603.02754, published at KDD ’16). The abstract names a sparsity-aware algorithm, a weighted quantile sketch, cache-access patterns, data compression and sharding as the system features behind its scalability.

How do you install XGBoost from the official source?

These commands come from the install page of the official XGBoost documentation (xgboost.readthedocs.io, stable, checked 2026-10-29). Use only one route per environment.

Environment Command or artifact from the docs
Python (pip) pip install xgboost
Python, smaller CPU-only build pip install xgboost-cpu
Python (conda) conda install -c conda-forge py-xgboost (the docs list py-xgboost=*=cpu* and py-xgboost=*=cuda* variants)
R install.packages('xgboost', repos = c('https://dmlc.r-universe.dev', 'https://cloud.r-project.org')) (R-universe is the recommended source; the docs mark the CRAN release as outdated)
JVM / Spark Artifact xgboost4j-spark_2.12, group ml.dmlc

Platform notes stated in the same documentation: on Windows, XGBoost needs DLLs from the Visual C++ Redistributable (not needed if Visual Studio is installed); GPU training (device=cuda:0) needs an NVIDIA GPU; macOS wheels have no GPU support; multi-GPU training is Linux only; on macOS, the R package needs brew install libomp, because without OpenMP XGBoost uses a single CPU core.

If you manage the project in a conda environment, sharing a reproducible conda environment shows how to record the exact versions.

Step by step: train, predict and save a model in Python

This is the sequence from the official Python introduction (checked 2026-10-29).

  1. Import the library: import xgboost as xgb.
  2. Wrap your NumPy array or pandas DataFrame in XGBoost’s data container: dtrain = xgb.DMatrix(data, label=label). Build dtest the same way from held-out rows.
  3. Set the parameters in a dictionary (param). The next section lists the documented defaults you are choosing between.
  4. Train: bst = xgb.train(param, dtrain, num_round, evallist), where num_round is the number of boosting rounds and evallist names the datasets whose metric is printed each round.
  5. Predict: ypred = bst.predict(dtest).
  6. Save: bst.save_model('model.ubj').

XGBoost also has a scikit-learn-style interface. The documentation example is reg = xgb.XGBRegressor(tree_method="hist", device="cuda"), followed by reg.fit(X, y) and reg.save_model("regressor.json"); leave out device to train on the CPU. If your analysis already runs through scikit-learn pipelines, the scikit-learn tutorial covers fitting, evaluating and citing in that ecosystem.

Output and how to read it

The prediction from bst.predict is the model’s output for each row of the test matrix, and the per-round lines from evallist are the evaluation metric. The documentation states that the default eval_metric depends on the objective: RMSE for regression and logloss for classification (other objectives, such as ranking, have their own defaults); the default objective is reg:squarederror.

What the objective and parameters mean

The official model tutorial writes the objective as obj(θ) = L(θ) + Ω(θ): a training loss plus a regularization term. It adds that “the regularization term is what people usually forget to add.” Training is additive: each round adds one tree, ft(x), to the previous prediction, using a second-order (gradient and Hessian) approximation so one solver serves many loss functions. The regularization is Ω(f) = γT + ½λΣwj², where T is the number of leaves and wj the leaf scores. A split is not added if its gain is below γ, which is how the tree is pruned.

Parameter Documented default What the docs say it does
eta (learning_rate) 0.3 Step size shrinkage used in update to prevent overfitting
max_depth 6 Maximum depth of a tree
lambda 1 L2 regularization term on weights
alpha 0 L1 regularization term on weights
gamma 0 Minimum loss reduction required to make a further partition on a leaf node of the tree
subsample 1 Subsample ratio of the training instances
objective reg:squarederror Regression with squared loss

Source: XGBoost Parameters page, checked 2026-10-29.

How should you report it in a paper?

Cite the method as Chen, T. and Guestrin, C. (2016), “XGBoost: A Scalable Tree Boosting System,” KDD ’16 (DOI 10.1145/2939672.2939785; arXiv DOI 10.48550/arXiv.1603.02754). State the library version you installed and every parameter you set; for any parameter you did not set, the documented default applies, and listing those values (for example eta 0.3 and max_depth 6) makes the run reproducible. Keep tuning decisions separate from the rows you evaluate on, since information from the test set leaking into training is the failure described under data leakage, and see computational reproducibility for what a rerun needs. For citing the software itself, how to cite software, code and R packages gives the patterns.

Troubleshooting installation and runs

  • Import fails on Windows: install the Visual C++ Redistributable, which provides DLLs XGBoost requires (not needed if Visual Studio is installed).
  • GPU not used on a Mac: macOS wheels have no GPU support; device=cuda:0 needs an NVIDIA GPU.
  • Training uses one core in R on macOS: run brew install libomp; without OpenMP XGBoost uses a single CPU core.
  • Old R version from CRAN: the docs mark the CRAN package as outdated; install from R-universe with the command above.
  • Spark on Windows: XGBoost4J-Spark does not support the Windows platform.
  • Multi-GPU training: supported only on Linux.

Free alternatives to XGBoost

The scikit-learn user guide (version 1.9.1, checked 2026-10-29) describes two gradient-boosted tree families that need no separate library.

Option What the scikit-learn documentation says
GradientBoostingClassifier / GradientBoostingRegressor Gradient Tree Boosting (GBDT) generalizes boosting to arbitrary differentiable loss functions; “an excellent model for both regression and classification, in particular for tabular data.” The page says these may be preferred for small sample sizes, since binning can make split points too approximate.
HistGradientBoostingClassifier / HistGradientBoostingRegressor Introduced in scikit-learn 0.21, inspired by LightGBM; can be orders of magnitude faster than the classes above when there are more than tens of thousands of samples; missing values are supported natively, with no imputer needed.

FAQ

Is XGBoost the same as a random forest?

No, but the models are closely related. The official tutorial says random forests and boosted trees are really the same kind of model; the difference arises from how they are trained. XGBoost trains its trees additively, each new tree added to the running prediction.

What does the regularization term do?

It penalizes model complexity: γ per leaf, and an L2 penalty λ on leaf scores. A split whose gain is below γ is not added. The docs’ default gamma is 0 and lambda is 1.

Can XGBoost run on a GPU?

Yes, with device=cuda:0 on a machine with an NVIDIA GPU. macOS wheels have no GPU support, and multi-GPU training is Linux only.

How do I install XGBoost for R?

The documentation recommends R-universe: install.packages('xgboost', repos = c('https://dmlc.r-universe.dev', 'https://cloud.r-project.org')).

Sources

  • XGBoost documentation, Installation Guide: https://xgboost.readthedocs.io/en/stable/install.html (checked 2026-10-29)
  • XGBoost documentation, Python Package Introduction: https://xgboost.readthedocs.io/en/stable/python/python_intro.html (checked 2026-10-29)
  • XGBoost documentation, Introduction to Boosted Trees: https://xgboost.readthedocs.io/en/stable/tutorials/model.html (checked 2026-10-29)
  • XGBoost documentation, XGBoost Parameters: https://xgboost.readthedocs.io/en/stable/parameter.html (checked 2026-10-29)
  • Chen, T. and Guestrin, C., XGBoost: A Scalable Tree Boosting System, arXiv:1603.02754, https://arxiv.org/abs/1603.02754 (checked 2026-10-29)
  • scikit-learn user guide, 1.11 Ensembles: https://scikit-learn.org/stable/modules/ensemble.html (version 1.9.1, checked 2026-10-29)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about What Is XGBoost? Install, Run and Read It for Research

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →