Previously I believe I could access through the env variable.
I don’t think so, these are the fields of the old env
parameter:
["model",
"cvfolds",
"iteration",
"begin_iteration",
"end_iteration",
"rank",
"evaluation_result_list"]
First, I’m trying to retrieve the original launch parameters for the XGBoost model config.
Since you, as the user, are passing those parameters into XGBoost, I think you can obtain those parameters without callback storing them:
callback = MyCallBack(parameters)
booster = xgboost.train(parameters, ... callback=[callback])
~~~~~~~~~~
or
callback = MyCallBack(parameters)
clf = xgboost.XGBClassifier(**parameters)
~~~~~~~~~~
clf.fit(X, y, callback=[callback])
In both cases, you have to know the parameters before start training right? If for some reason you have to get it from the callback itself, you can try booster.save_config()
with the model passed into callback.
Second, I want to pull the metrics that are evaluated in EvaluationMonitor as a one time pull after the training job is completed.
You can use the evals_result
parameter of xgboost.train
function, or xgboost.XGBRegressor.evals_result()
function. If you need to do it in your callback (I can’t think of the case that evals_result
not being sufficient, the example is just to answer you question instead of providing suggestion), then you can create a callback that does nothing until the last iteration:
results = {}
num_boost_round = 10
class MyCallBack(xgboost.TrainingCallback):
def after_iteration(self, model, epoch, evals_log):
if num_boost_round - 1 == epoch:
results.update(evals_log)
return False
xgboost.train(parameters, Xy, num_boost_round=num_boost_round, callback=[MyCallBack()]