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 = xgb.fit()

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
Metricsauto_metric_loggingCOMET_AUTO_LOG_METRICScomet.auto_log.metrics
Hyperparametersauto_param_loggingCOMET_AUTO_LOG_PARAMETERScomet.auto_log.parameters
Command-line argumentsparse_argsCOMET_AUTO_LOG_CLI_ARGUMENTScomet.auto_log.cli_arguments

End-to-end Example

# Get the data for this script:
# wget https://raw.githubusercontent.com/microsoft/LightGBM/master/examples/regression/regression.train -qq
# wget https://raw.githubusercontent.com/microsoft/LightGBM/master/examples/regression/regression.test -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)
model.fit(
    X_train,
    y_train,
    eval_set=[(X_train, y_train), (X_test, y_test)],
    eval_metric="rmse"
)

Try it out!

Here's an example for using Comet with XGBoost.

Open In Colab

Nov. 29, 2022