fix: improve metrics reliability and edge-case handling#875
Open
AhmedAli58 wants to merge 3 commits intosunlabuiuc:masterfrom
Open
fix: improve metrics reliability and edge-case handling#875AhmedAli58 wants to merge 3 commits intosunlabuiuc:masterfrom
AhmedAli58 wants to merge 3 commits intosunlabuiuc:masterfrom
Conversation
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.
Summary
This PR addresses three meaningful quality issues in the metrics layer, with regression tests.
Problem statements and fixes
regression_metrics_fnwas order-dependent becausekl_divergencemutated intermediate arrays used by later metrics.mse/maeremain unaffected by metric ordering.multilabel_metrics_fnmutatedy_predwhile computingddi, which could break subsequent metrics in the same call; it also returned onlyddi_scoreinstead of the requestedddikey.pred_labelslist (no mutation), returningddi, and preservingddi_scorefor backward compatibility.ranking_metrics_fnlacked robust validation and failed unclearly on edge cases (invalidk_values, empty score output).k_values, narrowed import error handling, and added an explicit error when evaluator output is empty.Impact
Tests
tests/core/test_metrics_quality.pywith regression coverage for all three issues.python -m py_compile pyhealth/metrics/regression.py pyhealth/metrics/multilabel.py pyhealth/metrics/ranking.py tests/core/test_metrics_quality.pyHOME=/tmp python -m unittest tests.core.test_metrics_quality -v