# XGBoost Python Feature Walkthrough

This is a collection of examples for using the XGBoost Python package.

<div id='sg-tag-list' class='sphx-glr-tag-list'></div><div class="sphx-glr-thumbnails">
<!-- thumbnail-parent-div-open --><div class="sphx-glr-thumbcontainer" tooltip="Demo for obtaining leaf index">![](python/examples/images/thumb/sphx_glr_predict_leaf_indices_thumb.png)

[Demo for obtaining leaf index](predict_leaf_indices.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for obtaining leaf index</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for using xgboost with sklearn">![](python/examples/images/thumb/sphx_glr_sklearn_parallel_thumb.png)

[Demo for using xgboost with sklearn](sklearn_parallel.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using xgboost with sklearn</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Shows how to train a model on the forest cover type dataset using GPU acceleration. The forest cover type dataset has 581,012 rows and 54 features, making it time consuming to process. We compare the run-time and accuracy of the GPU and CPU histogram algorithms.">![](python/examples/images/thumb/sphx_glr_cover_type_thumb.png)

[Using xgboost on GPU devices](cover_type.html.md)

  <div class="sphx-glr-thumbnail-title">Using xgboost on GPU devices</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="This script demonstrate how to access the eval metrics">![](python/examples/images/thumb/sphx_glr_evals_result_thumb.png)

[This script demonstrate how to access the eval metrics](evals_result.html.md)

  <div class="sphx-glr-thumbnail-title">This script demonstrate how to access the eval metrics</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for gamma regression">![](python/examples/images/thumb/sphx_glr_gamma_regression_thumb.png)

[Demo for gamma regression](gamma_regression.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for gamma regression</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for boosting from prediction">![](python/examples/images/thumb/sphx_glr_boost_from_prediction_thumb.png)

[Demo for boosting from prediction](boost_from_prediction.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for boosting from prediction</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for accessing the xgboost eval metrics by using sklearn interface">![](python/examples/images/thumb/sphx_glr_sklearn_evals_result_thumb.png)

[Demo for accessing the xgboost eval metrics by using sklearn interface](sklearn_evals_result.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for accessing the xgboost eval metrics by using sklearn interface</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="    .. versionadded:: 1.3.0">![](python/examples/images/thumb/sphx_glr_feature_weights_thumb.png)

[Demo for using feature weight to change column sampling](feature_weights.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using feature weight to change column sampling</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for GLM">![](python/examples/images/thumb/sphx_glr_generalized_linear_model_thumb.png)

[Demo for GLM](generalized_linear_model.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for GLM</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demonstrates using GPU acceleration to compute SHAP values for feature importance.">![](python/examples/images/thumb/sphx_glr_gpu_tree_shap_thumb.png)

[Use GPU to speedup SHAP value computation](gpu_tree_shap.html.md)

  <div class="sphx-glr-thumbnail-title">Use GPU to speedup SHAP value computation</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for prediction using number of trees">![](python/examples/images/thumb/sphx_glr_predict_first_ntree_thumb.png)

[Demo for prediction using number of trees](predict_first_ntree.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for prediction using number of trees</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="This is a simple example of using the native XGBoost interface, there are other interfaces in the Python package like scikit-learn interface and Dask interface.">![](python/examples/images/thumb/sphx_glr_basic_walkthrough_thumb.png)

[Getting started with XGBoost](basic_walkthrough.html.md)

  <div class="sphx-glr-thumbnail-title">Getting started with XGBoost</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Experimental support for categorical data.">![](python/examples/images/thumb/sphx_glr_categorical_thumb.png)

[Getting started with categorical data](categorical.html.md)

  <div class="sphx-glr-thumbnail-title">Getting started with categorical data</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="For an introduction to XGBoost&#x27;s scikit-learn estimator interface, see /python/sklearn_estimator.">![](python/examples/images/thumb/sphx_glr_sklearn_examples_thumb.png)

[Collection of examples for using sklearn interface](sklearn_examples.html.md)

  <div class="sphx-glr-thumbnail-title">Collection of examples for using sklearn interface</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for using cross validation">![](python/examples/images/thumb/sphx_glr_cross_validation_thumb.png)

[Demo for using cross validation](cross_validation.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using cross validation</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="See /tutorials/multioutput for more information.">![](python/examples/images/thumb/sphx_glr_multioutput_reduced_gradient_thumb.png)

[A demo for multi-output regression using reduced gradient](multioutput_reduced_gradient.html.md)

  <div class="sphx-glr-thumbnail-title">A demo for multi-output regression using reduced gradient</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Modifying existing trees is not a well established use for XGBoost, so feel free to experiment.">![](python/examples/images/thumb/sphx_glr_update_process_thumb.png)

[Demo for using process_type with prune and refresh](update_process.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using process_type with prune and refresh</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for prediction using individual trees and model slices">![](python/examples/images/thumb/sphx_glr_individual_trees_thumb.png)

[Demo for prediction using individual trees and model slices](individual_trees.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for prediction using individual trees and model slices</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="    .. versionadded:: 1.2.0">![](python/examples/images/thumb/sphx_glr_quantile_data_iterator_thumb.png)

[Demo for using data iterator with Quantile DMatrix](quantile_data_iterator.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using data iterator with Quantile DMatrix</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="@author: Weichen Xu">![](python/examples/images/thumb/sphx_glr_spark_estimator_examples_thumb.png)

[Collection of examples for using xgboost.spark estimator interface](spark_estimator_examples.html.md)

  <div class="sphx-glr-thumbnail-title">Collection of examples for using xgboost.spark estimator interface</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="A simple demo for categorical data support using dataset from Kaggle categorical data tutorial.">![](python/examples/images/thumb/sphx_glr_cat_in_the_dat_thumb.png)

[Train XGBoost with cat_in_the_dat dataset](cat_in_the_dat.html.md)

  <div class="sphx-glr-thumbnail-title">Train XGBoost with cat_in_the_dat dataset</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for training continuation">![](python/examples/images/thumb/sphx_glr_continuation_thumb.png)

[Demo for training continuation](continuation.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for training continuation</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="The demo is adopted from scikit-learn:">![](python/examples/images/thumb/sphx_glr_multioutput_regression_thumb.png)

[A demo for multi-output regression](multioutput_regression.html.md)

  <div class="sphx-glr-thumbnail-title">A demo for multi-output regression</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="The script showcases how to keep the categorical data encoding consistent across training and inference. There are many ways to attain the same goal, this script can be used as a starting point.">![](python/examples/images/thumb/sphx_glr_cat_pipeline_thumb.png)

[Feature engineering pipeline for categorical data](cat_pipeline.html.md)

  <div class="sphx-glr-thumbnail-title">Feature engineering pipeline for categorical data</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="    .. versionadded:: 1.3.0">![](python/examples/images/thumb/sphx_glr_callbacks_thumb.png)

[Demo for using and defining callback functions](callbacks.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for using and defining callback functions</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="  .. versionadded:: 2.0.0">![](python/examples/images/thumb/sphx_glr_learning_to_rank_thumb.png)

[Getting started with learning to rank](learning_to_rank.html.md)

  <div class="sphx-glr-thumbnail-title">Getting started with learning to rank</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="Demo for defining customized metric and objective.  Notice that for simplicity reason weight is not used in following example. In this script, we implement the Squared Log Error (SLE) objective and RMSLE metric as customized functions, then compare it with native implementation in XGBoost.">![](python/examples/images/thumb/sphx_glr_custom_rmsle_thumb.png)

[Demo for defining a custom regression objective and metric](custom_rmsle.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for defining a custom regression objective and metric</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="This is similar to the one in quantile_data_iterator.py, but for external memory instead of Quantile DMatrix.  The feature is not ready for production use yet.">![](python/examples/images/thumb/sphx_glr_external_memory_thumb.png)

[Experimental support for external memory](external_memory.html.md)

  <div class="sphx-glr-thumbnail-title">Experimental support for external memory</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="This demo is only applicable after (excluding) XGBoost 1.0.0, as before this version XGBoost returns transformed prediction for multi-class objective function.  More details in comments.">![](python/examples/images/thumb/sphx_glr_custom_softmax_thumb.png)

[Demo for creating customized multi-class objective function](custom_softmax.html.md)

  <div class="sphx-glr-thumbnail-title">Demo for creating customized multi-class objective function</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="    .. versionadded:: 2.0.0">![](python/examples/images/thumb/sphx_glr_prediction_intervals_thumb.png)

[Prediction Intervals with Quantile and Expectile Regression](prediction_intervals.html.md)

  <div class="sphx-glr-thumbnail-title">Prediction Intervals with Quantile and Expectile Regression</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="    .. versionadded:: 3.0.0">![](python/examples/images/thumb/sphx_glr_distributed_extmem_basic_thumb.png)

[Experimental support for distributed training with external memory](distributed_extmem_basic.html.md)

  <div class="sphx-glr-thumbnail-title">Experimental support for distributed training with external memory</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="See /tutorials/saving_model for details about the model serialization.">![](python/examples/images/thumb/sphx_glr_model_parser_thumb.png)

[Demonstration for parsing JSON/UBJSON tree model files](model_parser.html.md)

  <div class="sphx-glr-thumbnail-title">Demonstration for parsing JSON/UBJSON tree model files</div>
</div>
<!-- thumbnail-parent-div-close --></div>

[`Download all examples in Python source code: examples_python.zip`](_downloads/7f2330131fd6a3e3169422e46d470843/examples_python.zip)

[`Download all examples in Jupyter notebooks: examples_jupyter.zip`](_downloads/ee2631f53101fb5589baae8af8728750/examples_jupyter.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
