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

[metrics] Renaming of precision recall metric #3308

Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 13 additions & 13 deletions docs/source/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ FBeta
.. autoclass:: pytorch_lightning.metrics.classification.FBeta
:noindex:

PrecisionRecall
^^^^^^^^^^^^^^^
PrecisionRecallCurve
^^^^^^^^^^^^^^^^^^^^

.. autoclass:: pytorch_lightning.metrics.classification.PrecisionRecall
.. autoclass:: pytorch_lightning.metrics.classification.PrecisionRecallCurve
:noindex:

Precision
Expand Down Expand Up @@ -212,10 +212,10 @@ MulticlassROC
.. autoclass:: pytorch_lightning.metrics.classification.MulticlassROC
:noindex:

MulticlassPrecisionRecall
^^^^^^^^^^^^^^^^^^^^^^^^^
MulticlassPrecisionRecallCurve
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: pytorch_lightning.metrics.classification.MulticlassPrecisionRecall
.. autoclass:: pytorch_lightning.metrics.classification.MulticlassPrecisionRecallCurve
:noindex:

IoU
Expand Down Expand Up @@ -581,31 +581,31 @@ MeanAbsoluteError (sk)

.. autofunction:: pytorch_lightning.metrics.sklearns.MeanAbsoluteError
:noindex:

MeanSquaredError (sk)
^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: pytorch_lightning.metrics.sklearns.MeanSquaredError
:noindex:

MeanSquaredLogError (sk)
^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: pytorch_lightning.metrics.sklearns.MeanSquaredLogError
:noindex:

MedianAbsoluteError (sk)
^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: pytorch_lightning.metrics.sklearns.MedianAbsoluteError
:noindex:

R2Score (sk)
^^^^^^^^^^^^

.. autofunction:: pytorch_lightning.metrics.sklearns.R2Score
:noindex:

MeanPoissonDeviance (sk)
^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -617,10 +617,10 @@ MeanGammaDeviance (sk)

.. autofunction:: pytorch_lightning.metrics.sklearns.MeanGammaDeviance
:noindex:

MeanTweedieDeviance (sk)
^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: pytorch_lightning.metrics.sklearns.MeanTweedieDeviance
:noindex:

8 changes: 3 additions & 5 deletions pytorch_lightning/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
ROC,
AUROC,
DiceCoefficient,
MulticlassPrecisionRecall,
MulticlassPrecisionRecallCurve,
MulticlassROC,
Precision,
PrecisionRecall,
PrecisionRecallCurve,
IoU,
)
from pytorch_lightning.metrics.converters import numpy_metric, tensor_metric
Expand All @@ -27,7 +27,6 @@
)
from pytorch_lightning.metrics.sklearns import (
AUC,
PrecisionRecallCurve,
SklearnMetric,
)

Expand All @@ -40,10 +39,9 @@
"DiceCoefficient",
"F1",
"FBeta",
"MulticlassPrecisionRecall",
"MulticlassPrecisionRecallCurve",
"MulticlassROC",
"Precision",
"PrecisionRecall",
"PrecisionRecallCurve",
"ROC",
"Recall",
Expand Down
8 changes: 4 additions & 4 deletions pytorch_lightning/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ def forward(self, pred: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
normalize=self.normalize)


class PrecisionRecall(TensorCollectionMetric):
class PrecisionRecallCurve(TensorCollectionMetric):
"""
Computes the precision recall curve

Example:

>>> pred = torch.tensor([0, 1, 2, 3])
>>> target = torch.tensor([0, 1, 2, 2])
>>> metric = PrecisionRecall()
>>> metric = PrecisionRecallCurve()
>>> prec, recall, thr = metric(pred, target)
>>> prec
tensor([0.3333, 0.0000, 0.0000, 1.0000])
Expand Down Expand Up @@ -651,7 +651,7 @@ def forward(
num_classes=self.num_classes)


class MulticlassPrecisionRecall(TensorCollectionMetric):
class MulticlassPrecisionRecallCurve(TensorCollectionMetric):
"""Computes the multiclass PR Curve

Example:
Expand All @@ -661,7 +661,7 @@ class MulticlassPrecisionRecall(TensorCollectionMetric):
... [0.05, 0.05, 0.85, 0.05],
... [0.05, 0.05, 0.05, 0.85]])
>>> target = torch.tensor([0, 1, 3, 2])
>>> metric = MulticlassPrecisionRecall()
>>> metric = MulticlassPrecisionRecallCurve()
>>> metric(pred, target) # doctest: +NORMALIZE_WHITESPACE
((tensor([1., 1.]), tensor([1., 0.]), tensor([0.8500])),
(tensor([1., 1.]), tensor([1., 0.]), tensor([0.8500])),
Expand Down
8 changes: 4 additions & 4 deletions tests/metrics/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytorch_lightning.metrics.classification import (
Accuracy,
ConfusionMatrix,
PrecisionRecall,
PrecisionRecallCurve,
Precision,
Recall,
AveragePrecision,
Expand All @@ -17,7 +17,7 @@
F1,
ROC,
MulticlassROC,
MulticlassPrecisionRecall,
MulticlassPrecisionRecallCurve,
DiceCoefficient,
IoU,
)
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_confusion_matrix(normalize):
def test_precision_recall(pos_label):
pred, target = torch.tensor([1, 2, 3, 4]), torch.tensor([1, 0, 0, 1])

pr_curve = PrecisionRecall(pos_label=pos_label)
pr_curve = PrecisionRecallCurve(pos_label=pos_label)
assert pr_curve.name == 'precision_recall_curve'

pr = pr_curve(pred=pred, target=target, sample_weight=[0.1, 0.2, 0.3, 0.4])
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_multiclass_pr(num_classes):
[0.05, 0.05, 0.05, 0.85]])
target = torch.tensor([0, 1, 3, 2])

multi_pr = MulticlassPrecisionRecall(num_classes=num_classes)
multi_pr = MulticlassPrecisionRecallCurve(num_classes=num_classes)
assert multi_pr.name == 'multiclass_precision_recall_curve'

pr = multi_pr(pred, target)
Expand Down