Demo for defining a custom callback function that plots evaluation result during training.
()
| 60 | |
| 61 | |
| 62 | def 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 | |
| 89 | def check_point_callback() -> None: |
no test coverage detected