snowflake.ml.experiment.callback.xgboost.SnowflakeXgboostCallback

class snowflake.ml.experiment.callback.xgboost.SnowflakeXgboostCallback(experiment_tracking: ExperimentTracking, log_model: bool = True, log_metrics: bool = True, log_params: bool = True, log_every_n_epochs: int = 1, model_name: Optional[str] = None, version_name: Optional[str] = None, model_signature: Optional[ModelSignature] = None)

Bases: TrainingCallback

XGBoost callback for automatically logging to a Snowflake ML Experiment.

Initialize the callback.

Parameters:
  • experiment_tracking (ExperimentTracking) – The Experiment Tracking instance to use for logging.

  • log_model (bool) – Whether to log the model at the end of training. Default is True.

  • log_metrics (bool) – Whether to log metrics during training. Default is True.

  • log_params (bool) – Whether to log model parameters at the start of training. Default is True.

  • log_every_n_epochs (int) – Frequency with which to log metrics. Must be positive. Default is 1, logging after every iteration.

  • model_name (Optional[str]) – The model name to use when logging the model. If None, the model name will be derived from the experiment name.

  • version_name (Optional[str]) – The model version name to use when logging the model. If None, the version name will be randomly generated.

  • model_signature (Optional[ModelSignature]) – The model signature to use when logging the model. This is required if log_model is set to True.

Raises:

ValueError – When log_every_n_epochs is not a positive integer.

Methods

after_iteration(model: Any, epoch: int, evals_log: dict[str, dict[str, Any]]) bool

Run after each iteration. Returns True when training should stop.

Parameters:
  • model – Eeither a Booster object or a CVPack if the cv function in xgboost is being used.

  • epoch – The current training iteration.

  • evals_log

    A dictionary containing the evaluation history:

    {"data_name": {"metric_name": [0.5, ...]}}
    
    Copy

after_training(model: Booster) Booster

Run after training is finished.

before_training(model: Booster) Booster

Run before training starts.

Attributes

EvalsLog

alias of Dict[str, Dict[str, Union[List[float], List[Tuple[float, float]]]]]

alias of Dict[str, Dict[str, Union[List[float], List[Tuple[float, float]]]]] .. autoattribute:: SnowflakeXgboostCallback.EvalsLog