You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
compute_metrics keeps non-finite scores that calculate_metrics filters, and the CV objective can crash on an empty result #843
BaseModel.calculate_metrics skips metrics that return a non-finite value, with a warning that names the usual cause:
# DashAI/back/models/base_model.py:305-312score=metric.score(y_transformed, y_pred)
ifnotmath.isfinite(score):
logger.warning("Metric %s returned a non-finite value (%s) for split %s ""(e.g. only one class present in the split). Skipping.", ...)
continue
compute_metrics (line 339) copies that scoring loop without the guard:
A NaN from one fold poisons the whole trial.folds_results feeds np.mean(folds_results) at cv.py:244, which is the objective value the optimizer sees. One fold containing a single class makes the trial's score NaN, indistinguishable from a genuinely bad trial. calculate_metrics was written to avoid exactly this.
An empty dict raises KeyError. If compute_metrics takes any of its three early returns, validation_scores[metric.__name__] fails and the fold loop dies mid-trial, with a traceback pointing at a subscript rather than at the cause.
Suggested fix: share the scoring loop between the two methods, or add the same isfinite skip to compute_metrics. Either way it is worth deciding explicitly what a fold without the goal metric should do — skip that fold, or fail with a message that names the reason — rather than letting a KeyError decide.
Checked against develop @ b3b7296. Happy to send a PR if you tell me which of the two behaviours you want for the missing-metric case.
Thanks for the detailed report!. Both problems are real:
NaN poisoning: compute_metrics copies the scoring loop but drops the math.isfinite guard that calculate_metrics has. A single class fold writes a NaN into folds_results, and np.mean(folds_results) turns that trial's objective into NaN.
Silent KeyError: compute_metrics returns {} on all the same early exit paths as calculate_metrics, and cv.py:214 does validation_scores[metric.__name__] without checking, so a missing goal metric dies mid fold with a traceback pointing at the subscript, not the cause.
For the missing metric case, I'd prefer fail with a message that names the reason. A fold without the goal metric is almost always a configuration error (goal metric not in the configured metrics, or an empty split), so I'd rather surface it as a descriptive error than silently skip the fold. And I'd fix this by sharing one guarded scoring loop between calculate_metrics and compute_metrics so they can't drift again.
Activity
Irozuku commentedon Sep 8, 2026
Thanks for the detailed report!. Both problems are real:
NaN poisoning:
compute_metricscopies the scoring loop but drops the math.isfinite guard thatcalculate_metricshas. A single class fold writes aNaNintofolds_results, andnp.mean(folds_results)turns that trial's objective intoNaN.Silent
KeyError:compute_metricsreturns {} on all the same early exit paths ascalculate_metrics, and cv.py:214 doesvalidation_scores[metric.__name__]without checking, so a missing goal metric dies mid fold with a traceback pointing at the subscript, not the cause.For the missing metric case, I'd prefer fail with a message that names the reason. A fold without the goal metric is almost always a configuration error (goal metric not in the configured metrics, or an empty split), so I'd rather surface it as a descriptive error than silently skip the fold. And I'd fix this by sharing one guarded scoring loop between
calculate_metricsandcompute_metricsso they can't drift again.Please go ahead with the PR. Happy to review it.