Skip to content

Commit

Permalink
Switch plotting order for pr curves (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkafteNicki authored Nov 18, 2023
1 parent 28ac2b2 commit beae928
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deprecated `metric._update_called` ([#2141](https://github.com/Lightning-AI/torchmetrics/pull/2141))


- Changed x-/y-axis order for `PrecisionRecallCurve` to be consistent with scikit-learn ([#2183](https://github.com/Lightning-AI/torchmetrics/pull/2183))


### Removed

-
Expand Down
13 changes: 10 additions & 3 deletions src/torchmetrics/classification/precision_recall_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,16 @@ def plot(
"""
curve_computed = curve or self.compute()
# switch order as the standard way is recall along x-axis and precision along y-axis
curve_computed = (curve_computed[1], curve_computed[0], curve_computed[2])

score = (
_auc_compute_without_check(curve_computed[0], curve_computed[1], 1.0)
if not curve and score is True
else None
)
return plot_curve(
curve_computed, score=score, ax=ax, label_names=("Precision", "Recall"), name=self.__class__.__name__
curve_computed, score=score, ax=ax, label_names=("Recall", "Precision"), name=self.__class__.__name__
)


Expand Down Expand Up @@ -408,11 +411,13 @@ def plot(
"""
curve_computed = curve or self.compute()
# switch order as the standard way is recall along x-axis and precision along y-axis
curve_computed = (curve_computed[1], curve_computed[0], curve_computed[2])
score = (
_reduce_auroc(curve_computed[0], curve_computed[1], average=None) if not curve and score is True else None
)
return plot_curve(
curve_computed, score=score, ax=ax, label_names=("Precision", "Recall"), name=self.__class__.__name__
curve_computed, score=score, ax=ax, label_names=("Recall", "Precision"), name=self.__class__.__name__
)


Expand Down Expand Up @@ -598,11 +603,13 @@ def plot(
"""
curve_computed = curve or self.compute()
# switch order as the standard way is recall along x-axis and precision along y-axis
curve_computed = (curve_computed[1], curve_computed[0], curve_computed[2])
score = (
_reduce_auroc(curve_computed[0], curve_computed[1], average=None) if not curve and score is True else None
)
return plot_curve(
curve_computed, score=score, ax=ax, label_names=("Precision", "Recall"), name=self.__class__.__name__
curve_computed, score=score, ax=ax, label_names=("Recall", "Precision"), name=self.__class__.__name__
)


Expand Down

0 comments on commit beae928

Please sign in to comment.