MCPcopy Create free account
hub / github.com/dmlc/xgboost / custom_callback

Function custom_callback

demo/guide-python/callbacks.py:62–86  ·  view source on GitHub ↗

Demo for defining a custom callback function that plots evaluation result during training.

()

Source from the content-addressed store, hash-verified

60
61
62def custom_callback() -> None:
63 """Demo for defining a custom callback function that plots evaluation result during
64 training."""
65 X, y = load_breast_cancer(return_X_y=True)
66 X_train, X_valid, y_train, y_valid = train_test_split(X, y, random_state=0)
67
68 D_train = xgb.DMatrix(X_train, y_train)
69 D_valid = xgb.DMatrix(X_valid, y_valid)
70
71 num_boost_round = 100
72 plotting = Plotting(num_boost_round)
73
74 # Pass it to the `callbacks` parameter as a list.
75 xgb.train(
76 {
77 "objective": "binary:logistic",
78 "eval_metric": ["error", "rmse"],
79 "tree_method": "hist",
80 "device": "cuda",
81 },
82 D_train,
83 evals=[(D_train, "Train"), (D_valid, "Valid")],
84 num_boost_round=num_boost_round,
85 callbacks=[plotting],
86 )
87
88
89def check_point_callback() -> None:

Callers 1

callbacks.pyFile · 0.85

Calls 3

PlottingClass · 0.85
DMatrixMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected