Parent
#93
What to build
Add _compute_fold_metrics(y_true, y_pred) -> tuple[float, float, float] to _numeric_imputer.py. The function takes two numpy arrays — the true values and predicted values from a single k-fold validation fold — and returns (r2, rmse, mae) as a 3-tuple of floats. No model dependency, no Polars dependency, no I/O. Pure numpy/sklearn.
This function replaces the direct _r2_score(y_true, y_pred) call currently inlined inside the k-fold loops in _compute_regression_diagnostic, _compute_knn_diagnostics, and _compute_mice_diagnostics. Issue #227 wires it into those three loops and accumulates rmse_fold and mae_fold lists alongside the existing fold_r2s list.
The minimum-rows guard (n_complete < refit_r2_min_complete_rows) stays on the outer loop in each diagnostic function — _compute_fold_metrics is only called when the guard passes and the fold has variance. It does not handle the None case internally.
Acceptance criteria
Blocked by
Parent
#93
What to build
Add
_compute_fold_metrics(y_true, y_pred) -> tuple[float, float, float]to_numeric_imputer.py. The function takes two numpy arrays — the true values and predicted values from a single k-fold validation fold — and returns(r2, rmse, mae)as a 3-tuple of floats. No model dependency, no Polars dependency, no I/O. Pure numpy/sklearn.This function replaces the direct
_r2_score(y_true, y_pred)call currently inlined inside the k-fold loops in_compute_regression_diagnostic,_compute_knn_diagnostics, and_compute_mice_diagnostics. Issue #227 wires it into those three loops and accumulatesrmse_foldandmae_foldlists alongside the existingfold_r2slist.The minimum-rows guard (
n_complete < refit_r2_min_complete_rows) stays on the outer loop in each diagnostic function —_compute_fold_metricsis only called when the guard passes and the fold has variance. It does not handle theNonecase internally.Acceptance criteria
_compute_fold_metrics(y_true, y_pred)exists in_numeric_imputer.pyas a private functiontuple[float, float, float]of(r2, rmse, mae)rmseandmaeare non-negative for any finite inputrmse >= maealways holds (Cauchy-Schwarz inequality)rmse == 0.0andmae == 0.0wheny_pred == y_trueexactly (zero residuals)rmseandmaeare non-negativermse >= maeholdsrmse == 0.0andmae == 0.0when predictions equal targetsBlocked by