Add sample_weight to eval_metric (#8706)

This commit is contained in:
BenEfrati
2023-02-04 18:06:38 +02:00
committed by GitHub
parent dd79ab846f
commit 213b5602d9
2 changed files with 43 additions and 1 deletions

View File

@@ -119,7 +119,11 @@ def _metric_decorator(func: Callable) -> Metric:
def inner(y_score: np.ndarray, dmatrix: DMatrix) -> Tuple[str, float]:
y_true = dmatrix.get_label()
return func.__name__, func(y_true, y_score)
weight = dmatrix.get_weight()
if weight.size == 0:
return func.__name__, func(y_true, y_score)
else:
return func.__name__, func(y_true, y_score, sample_weight=weight)
return inner