Callbacks#
- class legateboost.TrainingCallback#
Interface for training callback.
- after_iteration(model: LBBase, epoch: int, evals_result: dict[str, dict[str, list[float]]]) bool #
Run after each iteration. Returns True when training should stop.
- Parameters:
model – Either a
Booster
object or a CVPack if the cv function in xgboost is being used.epoch – The current training iteration.
evals_result –
A dictionary containing the evaluation history:
{"data_name": {"metric_name": [0.5, ...]}}
- after_training(model: LBBase) None #
Run after training is finished.
- before_iteration(model: LBBase, epoch: int, evals_result: dict[str, dict[str, list[float]]]) bool #
Run before each iteration.
Returns True when training should stop. See
after_iteration()
for details.
- before_training(model: LBBase) None #
Run before training starts.
- class legateboost.EarlyStopping(rounds: int, metric_name: str | None = None, min_delta: float = 0.0, prune_model: bool = True, verbose: bool = False)#
Callback for early stopping during training. The last evaluation dataset is used for early stopping.
- Parameters:
rounds (int) – The number of rounds to wait for improvement before stopping.
metric_name (Optional[str]) – The name of the metric to monitor for improvement. If not provided, the last metric in the evaluation result will be used.
min_delta (float) – The minimum change in the monitored metric to be considered as improvement.
prune_model (bool) – Whether to prune the model after early stopping. If True, the model will be pruned to the best iteration.
- Raises:
ValueError – If min_delta is less than 0.
- after_iteration(model: LBBase, epoch: int, evals_result: dict[str, dict[str, list[float]]]) bool #
Run after each iteration. Returns True when training should stop.
- Parameters:
model – Either a
Booster
object or a CVPack if the cv function in xgboost is being used.epoch – The current training iteration.
evals_result –
A dictionary containing the evaluation history:
{"data_name": {"metric_name": [0.5, ...]}}
- after_training(model: LBBase) None #
Run after training is finished.
- before_training(model: LBBase) None #
Run before training starts.