Module Contents


neptune_callback(log_model=True, log_importance=True, max_num_features=None, log_tree=None, experiment=None, **kwargs)

XGBoost callback for Neptune experiments.

_log_model(booster, name, npt)

_log_importance(booster, max_num_features, npt, **kwargs)

_log_trees(booster, tree_list, img_name, npt, **kwargs)

neptunecontrib.monitoring.xgboost.neptune_callback(log_model=True, log_importance=True, max_num_features=None, log_tree=None, experiment=None, **kwargs)

XGBoost callback for Neptune experiments.

This is XGBoost callback that automatically logs training and evaluation metrics, feature importance chart, visualized trees and trained Booster to Neptune.

Check Neptune documentation for the full example.

Make sure you created an experiment before you start XGBoost training using neptune.create_experiment() (check our docs).

You need to install graphviz and graphviz Python interface for log_tree feature to work. Check Graphviz and Graphviz Python interface for installation info.

Integration works with xgboost>=1.2.0.


Use this Google Colab run it as a “neptuner” user - zero setup, it just works.


If you use early stopping, make sure to log model, feature importance and trees on your own. Neptune logs these artifacts only after last iteration, which you may not reach because of early stop.

  • log_model (bool, optional, default is True) –

    Log booster to Neptune after last boosting iteration.
    If you run, log booster for all folds.

  • log_importance (bool, optional, default is True) –

    Log feature importance to Neptune as image after last boosting iteration.
    Specify number of features using max_num_features parameter below.
    If you run, log feature importance for each folds’ booster.

  • max_num_features (int, optional, default is None) –

    Plot top max_num_features features on the importance plot.
    If None, plot all features.

  • log_tree (list of int, optional, default is None) –

    Log specified trees to Neptune as images after last boosting iteration.
    If you run, log specified trees for each folds’ booster.
    Default is None - do not log any tree.

  • experiment (neptune.experiments.Experiment, optional, default is None) –

    For advanced users only. Pass Neptune Experiment object if you want to control to which experiment data is logged.
    If None, log to currently active, and most recent experiment.

  • kwargs – Parametrize XGBoost functions used in this callback: xgboost.plot_importance and xgboost.to_graphviz.


callback, function that you can pass directly to the XGBoost callbacks list, for example to the (see docs) or (check docs).


xgb.train examples

# basic usage
xgb.train(param, dtrain, num_round, watchlist,

# do not log model
xgb.train(param, dtrain, num_round, watchlist,

# log top 5 features' importance chart
xgb.train(param, dtrain, num_round, watchlist,
          callbacks=[neptune_callback(max_num_features=5)]) examples

# log 5 trees per each folds' booster, dtrain, num_boost_round=num_round, nfold=7,

# log only metrics, dtrain, num_boost_round=num_round, nfold=7,

# log top 3 features per each folds' booster and first tree, dtrain, num_boost_round=num_round, nfold=7,

sklearn API examples

# basic usage with early stopping
xgb.XGBRegressor().fit(X_train, y_train,
                       eval_metric=['mae', 'rmse', 'rmsle'],
                       eval_set=[(X_test, y_test)],

# do not log model
clf = xgb.XGBRegressor(), y_train,
        eval_metric=['mae', 'rmse', 'rmsle'],
        eval_set=[(X_test, y_test)],
y_pred = clf.predict(X_test)

# log 8 trees
reg = xgb.XGBRegressor(**params), y_train,
        eval_metric=['mae', 'rmse', 'rmsle'],
        eval_set=[(X_test, y_test)],
neptunecontrib.monitoring.xgboost._log_model(booster, name, npt)
neptunecontrib.monitoring.xgboost._log_importance(booster, max_num_features, npt, **kwargs)
neptunecontrib.monitoring.xgboost._log_trees(booster, tree_list, img_name, npt, **kwargs)