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

Auroc error message #244

Merged
merged 4 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added pre-gather reduction in the case of `dist_reduce_fx="cat"` to reduce communication cost ([#217](https://github.com/PyTorchLightning/metrics/pull/217))


- Added better error message for `AUROC` when `num_classes` is not provided for multiclass input ([#244](https://github.com/PyTorchLightning/metrics/pull/244))


### Changed

Expand Down
8 changes: 8 additions & 0 deletions tests/classification/test_auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,11 @@ def test_error_on_different_mode():
with pytest.raises(ValueError, match=r"The mode of data.* should be constant.*"):
# pass in multi-label data
metric.update(torch.rand(10, 5), torch.randint(0, 2, (10, 5)))


def test_error_multiclass_no_num_classes():
with pytest.raises(
ValueError,
match="Detected input to ``multiclass`` but you did not provide ``num_classes`` argument"
):
_ = auroc(torch.randn(20, 3).softmax(dim=-1), torch.randint(3, (20, )))
2 changes: 2 additions & 0 deletions torchmetrics/functional/classification/auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def _auroc_compute(
fpr = [o[0] for o in output]
tpr = [o[1] for o in output]
else:
if mode != 'binary' and num_classes is None:
raise ValueError('Detected input to ``multiclass`` but you did not provide ``num_classes`` argument')
fpr, tpr, _ = roc(preds, target, num_classes, pos_label, sample_weights)

# calculate standard roc auc score
Expand Down