Repository navigation
Add support for edge cases - #19
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The updated binary/macro selection logic can still mis-handle multiclass folds that happen to contain labels {0,1}, producing incorrect metrics rather than just avoiding errors.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR addresses edge cases observed on real datasets by hardening evaluation and preprocessing utilities against NaN propagation, mis-detected classification task types in CV folds, and undersized spatial CV blocks.
Changes:
- Refines binary-vs-multiclass handling in
compute_classification_metricsto avoid invalid metric computation in certain folds. - Makes feature-importance aggregation NaN-aware so a single NaN run/fold doesn’t wipe out averages and standard deviations.
- Adds warnings when KMeans-generated spatial blocks are very small, since they can destabilize fold metrics/interpretation.
File summaries
| File | Description |
|---|---|
| ecosci/evaluation/metrics.py | Adjusts how average mode is selected for precision/recall/F1 to better handle edge cases in CV folds. |
| ecosci/evaluation/feature_importance.py | Switches seed/fold aggregation to nanmean/nanstd to prevent NaNs from propagating through summary importances. |
| ecosci/data/spatial.py | Warns when spatial blocks are extremely small, which can cause unstable or undefined fold-level evaluation in some settings. |
Review details
Suppressed comments (1)
ecosci/evaluation/feature_importance.py:281
- Similarly here, the comment attributes NaNs to R^2 being undefined for <2-sample test sets, but that only applies when using R^2 scoring (regression). Qualifying this avoids confusion since classification permutation importance uses accuracy and won’t hit this specific NaN path.
# Average importances across all folds (nan-aware: a fold whose test
# set has fewer than 2 samples makes permutation importance's R^2
# scorer undefined for that fold, and a plain mean would let that
# one NaN-only fold wipe out every feature's average)
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+52
to
+58
| print( | ||
| f"Warning: {n_singleton} of {n_blocks} spatial block(s) have fewer than " | ||
| f"2 samples (smallest: {min_count}). A CV fold built from one of these " | ||
| f"has an undefined test-set R^2/variance and will show up as NaN in " | ||
| f"per-fold metrics and permutation-based feature importance. Consider " | ||
| f"lowering n_blocks (currently {n_blocks})." | ||
| ) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are bugs/issues that came up while using the code on a variety of real datasets.