Skip to content

Scope 4.2: Implement _compute_fold_metrics() helper for per-fold RMSE and MAE #226

Description

@DEVunderdog

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

  • _compute_fold_metrics(y_true, y_pred) exists in _numeric_imputer.py as a private function
  • Returns tuple[float, float, float] of (r2, rmse, mae)
  • rmse and mae are non-negative for any finite input
  • rmse >= mae always holds (Cauchy-Schwarz inequality)
  • rmse == 0.0 and mae == 0.0 when y_pred == y_true exactly (zero residuals)
  • Unit test: returns a 3-tuple of floats for a simple predictable case (e.g. constant target perfectly predicted)
  • Unit test: rmse and mae are non-negative
  • Unit test: rmse >= mae holds
  • Unit test: rmse == 0.0 and mae == 0.0 when predictions equal targets

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions