[CI] Fix custom metric test with empty dataset. (#6917)

This commit is contained in:
Jiaming Yuan 2021-04-30 09:00:05 +08:00 committed by GitHub
parent db6285fb55
commit b31d37eac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,6 +272,8 @@ def eval_error_metric(predt, dtrain: xgb.DMatrix):
label = dtrain.get_label()
r = np.zeros(predt.shape)
gt = predt > 0.5
if predt.size == 0:
return "CustomErr", 0
r[gt] = 1 - label[gt]
le = predt <= 0.5
r[le] = label[le]