refactor(metrics): warn with the remaining count and document NaN pairs (SIENTIAPDE-2215)
This commit is contained in:
@@ -357,7 +357,8 @@ class DataManagerRepository(SientiaMonitoring):
|
||||
This helper mirrors the previous TrainingRepository.after_train_calculation
|
||||
behavior, assuming that predictions (y_pred/y_train_pred) are already on the
|
||||
correct scale for metric calculation (any scaling is handled inside the
|
||||
model wrapper).
|
||||
model wrapper). Pairs with a NaN target or a NaN prediction are left out of
|
||||
mse/mae/r2.
|
||||
|
||||
Args:
|
||||
tmr: Training result containing:
|
||||
@@ -368,6 +369,10 @@ class DataManagerRepository(SientiaMonitoring):
|
||||
|
||||
Return:
|
||||
TrainModelResult: Same object with mse_val, mae_val and r2_val set.
|
||||
|
||||
Raises:
|
||||
ValueError: If y_pred is not set, val_data and y_pred share no indices,
|
||||
or no pair has both a valid target and a valid prediction.
|
||||
"""
|
||||
if tmr.y_pred is None:
|
||||
raise ValueError('y_pred must be set before computing regression metrics')
|
||||
@@ -414,9 +419,10 @@ class DataManagerRepository(SientiaMonitoring):
|
||||
f'{len(valid)} overlapping rows have NaN'
|
||||
)
|
||||
if not valid.all():
|
||||
self.info(
|
||||
f'Ignoring {int((~valid).sum())} validation row(s) with NaN target or prediction '
|
||||
'in the regression metrics',
|
||||
n_valid = int(valid.sum())
|
||||
self.warning(
|
||||
f'Ignoring {len(valid) - n_valid} of {len(valid)} validation row(s) with NaN '
|
||||
f'target or prediction; regression metrics use the remaining {n_valid}',
|
||||
metadata,
|
||||
)
|
||||
y_true_val = y_true_val[valid]
|
||||
|
||||
Reference in New Issue
Block a user