Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update R2 score to handle single sample computation #2235

Merged

Conversation

arnavgarg1
Copy link
Contributor

@arnavgarg1 arnavgarg1 commented Jul 6, 2022

One of the users in Ludwig's OSS reported an issue with R2 computation in v0.5 where R2 scores can't be computed if the sample size during prediction is just 1 row. The error torchmetrics returns is logically correct because R2 scores can't be calculated for just one sample.

This PR updates the implementation of R2 to return NaN when one sample is used for R2 computation and logs a user-facing warning to use two or more samples for non NaN R2 score calculation.

@arnavgarg1 arnavgarg1 linked an issue Jul 6, 2022 that may be closed by this pull request
@arnavgarg1 arnavgarg1 changed the title Update R2 scores to handle single sample computation Update R2 score to handle single sample computation Jul 6, 2022
@github-actions
Copy link

github-actions bot commented Jul 6, 2022

Unit Test Results

       6 files  +    1         6 suites  +1   2h 25m 37s ⏱️ + 33m 7s
2 915 tests +    2  2 869 ✔️ +    2    46 💤 ±  0  0 ±0 
8 745 runs  +174  8 603 ✔️ +151  142 💤 +23  0 ±0 

Results for commit 363748c. ± Comparison against base commit cd4815b.

♻️ This comment has been updated with latest results.

@arnavgarg1 arnavgarg1 marked this pull request as ready for review July 6, 2022 08:24
ludwig/modules/metric_modules.py Outdated Show resolved Hide resolved
tests/ludwig/modules/test_metric_modules.py Outdated Show resolved Hide resolved
tests/ludwig/modules/test_metric_modules.py Outdated Show resolved Hide resolved
@arnavgarg1 arnavgarg1 self-assigned this Jul 6, 2022
@arnavgarg1 arnavgarg1 merged commit dfdc98c into master Jul 6, 2022
@arnavgarg1 arnavgarg1 deleted the 2234-r2-score-cant-be-computed-for-single-samples branch July 6, 2022 21:17
arnavgarg1 added a commit that referenced this pull request Aug 2, 2022
* Update R2 scores to handle single sample computation
arnavgarg1 added a commit that referenced this pull request Aug 2, 2022
* Update R2 scores to handle single sample computation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

R2 score can't be computed for single samples
3 participants