class_docstr: `WandbCallback` automatically integrates XGBoost with wandb.
  
  Arguments:
      log_model: (boolean) if True save and upload the model to Weights & Biases Artifacts
      log_feature_importance: (boolean) if True log a feature importance bar plot
      importance_type: (str) one of {weight, gain, cover, total_gain, total_cover} for tree model. weight for linear model.
      define_metric: (boolean) if True (default) capture model performance at the best step, instead of the last step, of training in your `wandb.summary`.
  
  Passing `WandbCallback` to XGBoost will:
  
  - log the booster model configuration to Weights & Biases
  - log evaluation metrics collected by XGBoost, such as rmse, accuracy etc. to Weights & Biases
  - log training metric collected by XGBoost (if you provide training data to eval_set)
  - log the best score and the best iteration
  - save and upload your trained model to Weights & Biases Artifacts (when `log_model = True`)
  - log feature importance plot when `log_feature_importance=True` (default).
  - Capture the best eval metric in `wandb.summary` when `define_metric=True` (default).
  
  Example:
      ```python
      bst_params = dict(
          objective="reg:squarederror",
          colsample_bytree=0.3,
          learning_rate=0.1,
          max_depth=5,
          alpha=10,
          n_estimators=10,
          tree_method="hist",
          callbacks=[WandbCallback()],
      )
  
      xg_reg = xgb.XGBRegressor(**bst_params)
      xg_reg.fit(
          X_train,
          y_train,
          eval_set=[(X_test, y_test)],
      )
      ```
class_docstr_tok: ["`","WandbCallback","`","automatically","integrates","XGBoost","with","wandb",".","Arguments",":","log_model",":","(","boolean",")","if","True","save","and","upload","the","model","to","Weights","&","Biases","Artifacts","log_feature_importance",":","(","boolean",")","if","True","log","a","feature","importance","bar","plot","importance_type",":","(","str",")","one","of","{","weight",",","gain",",","cover",",","total_gain",",","total_cover","}","for","tree","model",".","weight","for","linear","model",".","define_metric",":","(","boolean",")","if","True","(","default",")","capture","model","performance","at","the","best","step",",","instead","of","the","last","step",",","of","training","in","your","`","wandb.summary","`",".","Passing","`","WandbCallback","`","to","XGBoost","will",":","-","log","the","booster","model","configuration","to","Weights","&","Biases","-","log","evaluation","metrics","collected","by","XGBoost",",","such","as","rmse",",","accuracy","etc",".","to","Weights","&","Biases","-","log","training","metric","collected","by","XGBoost","(","if","you","provide","training","data","to","eval_set",")","-","log","the","best","score","and","the","best","iteration","-","save","and","upload","your","trained","model","to","Weights","&","Biases","Artifacts","(","when","`","log_model","=","True","`",")","-","log","feature","importance","plot","when","`","log_feature_importance=True","`","(","default",")",".","-","Capture","the","best","eval","metric","in","`","wandb.summary","`","when","`","define_metric=True","`","(","default",")",".","Example",":","``","`","python","bst_params","=","dict","(","objective=","''","reg",":","squarederror","''",",","colsample_bytree=0.3",",","learning_rate=0.1",",","max_depth=5",",","alpha=10",",","n_estimators=10",",","tree_method=","''","hist","''",",","callbacks=","[","WandbCallback","(",")","]",",",")","xg_reg","=","xgb.XGBRegressor","(","*","*","bst_params",")","xg_reg.fit","(","X_train",",","y_train",",","eval_set=","[","(","X_test",",","y_test",")","]",",",")","``","`"]
docstr: Run after each iteration. Return True when training should stop.
docstr_tok: ["Run","after","each","iteration",".","Return","True","when","training","should","stop","."]
code: def after_iteration(
      self, model: Booster, epoch: int, evals_log: dict
  ) -> bool:
      """Run after each iteration. Return True when training should stop."""
      # Log metrics
      for data, metric in evals_log.items():
          for metric_name, log in metric.items():
              if self.define_metric:
                  self._define_metric(data, metric_name)
                  wandb.log(
                      {f"{data}-{metric_name}": log[-1]}, commit=False
                  )
              else:
                  wandb.log(
                      {f"{data}-{metric_name}": log[-1]}, commit=False
                  )
  
      wandb.log({"epoch": epoch})
  
      self.define_metric = False
  
      return False
  
file_path: wandb/wandb/integration/xgboost/xgboost.py
imports: import json
  import warnings
  from pathlib import Path
  from typing import TYPE_CHECKING, cast
  import xgboost
  from xgboost import Booster
  import wandb
  from wandb.sdk.lib import telemetry
label_desc: Use image node_id 4 for calling the WandbCallback obj's underlying member method code with example usage: obj.after_iteration(model, epoch, evals_log) and returns: False