Fix NMI/AMI returning 0.0 instead of 1.0 for two single-cluster labelings - #3470
Open
AlejandroCoronadoN wants to merge 2 commits into
Open
Fix NMI/AMI returning 0.0 instead of 1.0 for two single-cluster labelings#3470AlejandroCoronadoN wants to merge 2 commits into
AlejandroCoronadoN wants to merge 2 commits into
Conversation
AlejandroCoronadoN
requested review from
SkafteNicki and
justusschock
as code owners
August 20, 2026 03:33
justusschock
approved these changes
Aug 20, 2026
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3470 +/- ##
=======================================
- Coverage 37% 33% -4%
=======================================
Files 349 349
Lines 19901 19914 +13
=======================================
- Hits 7264 6524 -740
- Misses 12637 13390 +753 🚀 New features to boost your workflow:
|
Author
|
Thanks for the review, @justusschock. This has drifted a bit behind master; happy to rebase it if that helps it land, and glad to make any other changes you need. |
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.
Fixes #3469.
normalized_mutual_info_scoreandadjusted_mutual_info_scorereturn0.0when bothpredsandtargetare a single cluster (two zero-entropy labelings). scikit-learn, the documented reference for these metrics, returns1.0for this limit case because the two labelings trivially agree.Repro:
Fix: return
1.0early when both labelings have exactly one unique value, matching sklearn. Foradjusted_mutual_info_scoreI also added thecheck_cluster_labels(preds, target)call that the other clustering metrics already use, so the early return does not bypass input validation (float inputs still raise, verified). No non-degenerate result changes.Tests: added a
both_single_clustercase parametrized over everyaverage_methodto both functional test files, using sklearn as the reference oracle.ruffis clean.