Skip to content

Integrate with XGBoost

Comet integrates with XGBoost.

XGBoost is an optimized distributed gradient boosting library designed to be highly efficient, flexible and portable. It implements machine learning algorithms under the Gradient Boosting framework. XGBoost provides a parallel tree boosting (also known as GBDT, GBM) that solve many data science problems in a fast and accurate way. The same code runs on major distributed environment (Kubernetes, Hadoop, SGE, MPI, Dask) and can solve problems beyond billions of examples.

from comet_ml import Experiment
import xgboost as xgb

experiment = Experiment()

# Your code here...
model =

Log automatically

The Comet XGBoost auto-logger can automatically log:

  • Model/graph description
  • Metrics (such as loss and accuracy)
  • Hyperparameters
  • Command-line arguments

Configure Comet for XGBoost

ItemExperiment ParameterEnvironment SettingConfiguration File Setting
Model/graph descriptionlog_graphCOMET_AUTO_LOG_GRAPHcomet.auto_log.graph
Command-line argumentsparse_argsCOMET_AUTO_LOG_CLI_ARGUMENTScomet.auto_log.cli_arguments

End-to-end Example

# Get the data for this script:
# wget -qq
# wget -qq
import comet_ml

import xgboost as xgb
import os
import pandas as pd
from sklearn.metrics import mean_squared_error

experiment = comet_ml.Experiment()

dirname = os.path.dirname(__file__)
df_train = pd.read_csv(os.path.join(dirname, "regression.train"), header=None, sep="\t")
df_test = pd.read_csv(os.path.join(dirname, "regression.test"), header=None, sep="\t")

y_train = df_train[0]
y_test = df_test[0]

X_train = df_train.drop(0, axis=1)
X_test = df_test.drop(0, axis=1)

param = {
    "objective": "reg:squarederror",
    "colsample_bytree": 0.3,
    "learning_rate": 0.1,
    "max_depth": 5,
    "alpha": 10,
    "n_estimators": 50,

model = xgb.XGBRegressor(**param)
    eval_set=[(X_train, y_train), (X_test, y_test)],

Try it out!

Here's an example for using Comet with XGBoost.

Open In Colab

May. 17, 2022