Lightning-AI / Lightning-AI/torchmetrics

V-measure returns 1 for independent nontrivial clusterings

Open Beginner friendly
#3,484 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.5k
Forks
526
Avg merge
6d 11h
Merged PRs (30d)
5

Description

For two independent, nontrivial clusterings, both homogeneity and completeness are zero, but `v_measure_score` currently returns `1.0`.

```python
import torch
from torchmetrics.functional.clustering import v_measure_score

preds = torch.tensor([0, 1, 0, 1])
target = torch.tensor([0, 0, 1, 1])

print(v_measure_score(preds, target)) # tensor(1.)
```

scikit-learn returns `0.0` for the same labels. That also matches the weighted harmonic mean definition: when both component scores are zero, V-measure should be zero.

This reproduces on current `master` (`8d008de1`) with Python 3.12.13 and PyTorch 2.13.0. I have a small fix and regression test ready. I also checked the edge case with a small Lean formalization and can attach it if useful :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the torchmetrics.functional.clustering.v_measure_score entry point and run the supplied tensor example to reproduce the incorrect tensor(1.) result. Add the regression test described in the issue and verify that independent nontrivial clusterings return 0.0, while existing V-measure behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.