diff --git a/src/torchmetrics/functional/classification/hamming.py b/src/torchmetrics/functional/classification/hamming.py index ed47ce56982..8c03528f908 100644 --- a/src/torchmetrics/functional/classification/hamming.py +++ b/src/torchmetrics/functional/classification/hamming.py @@ -163,7 +163,7 @@ def multiclass_hamming_distance( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -231,7 +231,7 @@ def multiclass_hamming_distance( >>> target = tensor([2, 1, 0, 0]) >>> preds = tensor([2, 1, 0, 1]) >>> multiclass_hamming_distance(preds, target, num_classes=3) - tensor(0.1667) + tensor(0.2500) >>> multiclass_hamming_distance(preds, target, num_classes=3, average=None) tensor([0.5000, 0.0000, 0.0000]) @@ -243,7 +243,7 @@ def multiclass_hamming_distance( ... [0.71, 0.09, 0.20], ... [0.05, 0.82, 0.13]]) >>> multiclass_hamming_distance(preds, target, num_classes=3) - tensor(0.1667) + tensor(0.2500) >>> multiclass_hamming_distance(preds, target, num_classes=3, average=None) tensor([0.5000, 0.0000, 0.0000]) @@ -252,7 +252,7 @@ def multiclass_hamming_distance( >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]]) >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]]) >>> multiclass_hamming_distance(preds, target, num_classes=3, multidim_average='samplewise') - tensor([0.5000, 0.7222]) + tensor([0.5000, 0.6667]) >>> multiclass_hamming_distance(preds, target, num_classes=3, multidim_average='samplewise', average=None) tensor([[0.0000, 1.0000, 0.5000], [1.0000, 0.6667, 0.5000]]) @@ -273,7 +273,7 @@ def multilabel_hamming_distance( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True, diff --git a/src/torchmetrics/functional/classification/negative_predictive_value.py b/src/torchmetrics/functional/classification/negative_predictive_value.py index 65297e0c7e6..a3980d6c493 100644 --- a/src/torchmetrics/functional/classification/negative_predictive_value.py +++ b/src/torchmetrics/functional/classification/negative_predictive_value.py @@ -139,7 +139,7 @@ def multiclass_negative_predictive_value( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -208,7 +208,7 @@ def multiclass_negative_predictive_value( >>> target = tensor([2, 1, 0, 0]) >>> preds = tensor([2, 1, 0, 1]) >>> multiclass_negative_predictive_value(preds, target, num_classes=3) - tensor(0.8889) + tensor(0.8750) >>> multiclass_negative_predictive_value(preds, target, num_classes=3, average=None) tensor([0.6667, 1.0000, 1.0000]) @@ -220,7 +220,7 @@ def multiclass_negative_predictive_value( ... [0.71, 0.09, 0.20], ... [0.05, 0.82, 0.13]]) >>> multiclass_negative_predictive_value(preds, target, num_classes=3) - tensor(0.8889) + tensor(0.8750) >>> multiclass_negative_predictive_value(preds, target, num_classes=3, average=None) tensor([0.6667, 1.0000, 1.0000]) @@ -229,7 +229,7 @@ def multiclass_negative_predictive_value( >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]]) >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]]) >>> multiclass_negative_predictive_value(preds, target, num_classes=3, multidim_average='samplewise') - tensor([0.7833, 0.6556]) + tensor([0.7500, 0.6667]) >>> multiclass_negative_predictive_value( ... preds, target, num_classes=3, multidim_average='samplewise', average=None ... ) @@ -254,7 +254,7 @@ def multilabel_negative_predictive_value( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True, @@ -320,7 +320,7 @@ def multilabel_negative_predictive_value( >>> target = tensor([[0, 1, 0], [1, 0, 1]]) >>> preds = tensor([[0, 0, 1], [1, 0, 1]]) >>> multilabel_negative_predictive_value(preds, target, num_labels=3) - tensor(0.5000) + tensor(0.6667) >>> multilabel_negative_predictive_value(preds, target, num_labels=3, average=None) tensor([1.0000, 0.5000, 0.0000]) @@ -329,7 +329,7 @@ def multilabel_negative_predictive_value( >>> target = tensor([[0, 1, 0], [1, 0, 1]]) >>> preds = tensor([[0.11, 0.22, 0.84], [0.73, 0.33, 0.92]]) >>> multilabel_negative_predictive_value(preds, target, num_labels=3) - tensor(0.5000) + tensor(0.6667) >>> multilabel_negative_predictive_value(preds, target, num_labels=3, average=None) tensor([1.0000, 0.5000, 0.0000]) @@ -339,7 +339,7 @@ def multilabel_negative_predictive_value( >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]], ... [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]]) >>> multilabel_negative_predictive_value(preds, target, num_labels=3, multidim_average='samplewise') - tensor([0.0000, 0.1667]) + tensor([0.0000, 0.2500]) >>> multilabel_negative_predictive_value( ... preds, target, num_labels=3, multidim_average='samplewise', average=None ... ) diff --git a/src/torchmetrics/functional/classification/precision_recall.py b/src/torchmetrics/functional/classification/precision_recall.py index 96214c82274..d1cbb609e99 100644 --- a/src/torchmetrics/functional/classification/precision_recall.py +++ b/src/torchmetrics/functional/classification/precision_recall.py @@ -141,7 +141,7 @@ def multiclass_precision( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -209,7 +209,7 @@ def multiclass_precision( >>> target = tensor([2, 1, 0, 0]) >>> preds = tensor([2, 1, 0, 1]) >>> multiclass_precision(preds, target, num_classes=3) - tensor(0.8333) + tensor(0.7500) >>> multiclass_precision(preds, target, num_classes=3, average=None) tensor([1.0000, 0.5000, 1.0000]) @@ -221,7 +221,7 @@ def multiclass_precision( ... [0.71, 0.09, 0.20], ... [0.05, 0.82, 0.13]]) >>> multiclass_precision(preds, target, num_classes=3) - tensor(0.8333) + tensor(0.7500) >>> multiclass_precision(preds, target, num_classes=3, average=None) tensor([1.0000, 0.5000, 1.0000]) @@ -230,7 +230,7 @@ def multiclass_precision( >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]]) >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]]) >>> multiclass_precision(preds, target, num_classes=3, multidim_average='samplewise') - tensor([0.3889, 0.2778]) + tensor([0.5000, 0.3333]) >>> multiclass_precision(preds, target, num_classes=3, multidim_average='samplewise', average=None) tensor([[0.6667, 0.0000, 0.5000], [0.0000, 0.5000, 0.3333]]) @@ -261,7 +261,7 @@ def multilabel_precision( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True, @@ -326,7 +326,7 @@ def multilabel_precision( >>> target = tensor([[0, 1, 0], [1, 0, 1]]) >>> preds = tensor([[0, 0, 1], [1, 0, 1]]) >>> multilabel_precision(preds, target, num_labels=3) - tensor(0.5000) + tensor(0.6667) >>> multilabel_precision(preds, target, num_labels=3, average=None) tensor([1.0000, 0.0000, 0.5000]) @@ -335,7 +335,7 @@ def multilabel_precision( >>> target = tensor([[0, 1, 0], [1, 0, 1]]) >>> preds = tensor([[0.11, 0.22, 0.84], [0.73, 0.33, 0.92]]) >>> multilabel_precision(preds, target, num_labels=3) - tensor(0.5000) + tensor(0.6667) >>> multilabel_precision(preds, target, num_labels=3, average=None) tensor([1.0000, 0.0000, 0.5000]) @@ -345,7 +345,7 @@ def multilabel_precision( >>> preds = tensor([[[0.59, 0.91], [0.91, 0.99], [0.63, 0.04]], ... [[0.38, 0.04], [0.86, 0.780], [0.45, 0.37]]]) >>> multilabel_precision(preds, target, num_labels=3, multidim_average='samplewise') - tensor([0.3333, 0.0000]) + tensor([0.4000, 0.0000]) >>> multilabel_precision(preds, target, num_labels=3, multidim_average='samplewise', average=None) tensor([[0.5000, 0.5000, 0.0000], [0.0000, 0.0000, 0.0000]]) @@ -451,7 +451,7 @@ def multiclass_recall( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -519,7 +519,7 @@ def multiclass_recall( >>> target = tensor([2, 1, 0, 0]) >>> preds = tensor([2, 1, 0, 1]) >>> multiclass_recall(preds, target, num_classes=3) - tensor(0.8333) + tensor(0.7500) >>> multiclass_recall(preds, target, num_classes=3, average=None) tensor([0.5000, 1.0000, 1.0000]) @@ -531,7 +531,7 @@ def multiclass_recall( ... [0.71, 0.09, 0.20], ... [0.05, 0.82, 0.13]]) >>> multiclass_recall(preds, target, num_classes=3) - tensor(0.8333) + tensor(0.7500) >>> multiclass_recall(preds, target, num_classes=3, average=None) tensor([0.5000, 1.0000, 1.0000]) @@ -540,7 +540,7 @@ def multiclass_recall( >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]]) >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]]) >>> multiclass_recall(preds, target, num_classes=3, multidim_average='samplewise') - tensor([0.5000, 0.2778]) + tensor([0.5000, 0.3333]) >>> multiclass_recall(preds, target, num_classes=3, multidim_average='samplewise', average=None) tensor([[1.0000, 0.0000, 0.5000], [0.0000, 0.3333, 0.5000]]) @@ -571,7 +571,7 @@ def multilabel_recall( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True, diff --git a/src/torchmetrics/functional/classification/specificity.py b/src/torchmetrics/functional/classification/specificity.py index 112a7b96204..9e59ea537aa 100644 --- a/src/torchmetrics/functional/classification/specificity.py +++ b/src/torchmetrics/functional/classification/specificity.py @@ -132,7 +132,7 @@ def multiclass_specificity( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -198,7 +198,7 @@ def multiclass_specificity( >>> target = tensor([2, 1, 0, 0]) >>> preds = tensor([2, 1, 0, 1]) >>> multiclass_specificity(preds, target, num_classes=3) - tensor(0.8889) + tensor(0.8750) >>> multiclass_specificity(preds, target, num_classes=3, average=None) tensor([1.0000, 0.6667, 1.0000]) @@ -210,7 +210,7 @@ def multiclass_specificity( ... [0.71, 0.09, 0.20], ... [0.05, 0.82, 0.13]]) >>> multiclass_specificity(preds, target, num_classes=3) - tensor(0.8889) + tensor(0.8750) >>> multiclass_specificity(preds, target, num_classes=3, average=None) tensor([1.0000, 0.6667, 1.0000]) @@ -219,7 +219,7 @@ def multiclass_specificity( >>> target = tensor([[[0, 1], [2, 1], [0, 2]], [[1, 1], [2, 0], [1, 2]]]) >>> preds = tensor([[[0, 2], [2, 0], [0, 1]], [[2, 2], [2, 1], [1, 0]]]) >>> multiclass_specificity(preds, target, num_classes=3, multidim_average='samplewise') - tensor([0.7500, 0.6556]) + tensor([0.7500, 0.6667]) >>> multiclass_specificity(preds, target, num_classes=3, multidim_average='samplewise', average=None) tensor([[0.7500, 0.7500, 0.7500], [0.8000, 0.6667, 0.5000]]) @@ -240,7 +240,7 @@ def multilabel_specificity( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True, diff --git a/src/torchmetrics/functional/classification/stat_scores.py b/src/torchmetrics/functional/classification/stat_scores.py index 0d32bef573a..66e38d90b7a 100644 --- a/src/torchmetrics/functional/classification/stat_scores.py +++ b/src/torchmetrics/functional/classification/stat_scores.py @@ -220,7 +220,7 @@ def binary_stat_scores( def _multiclass_stat_scores_arg_validation( num_classes: int, top_k: int = 1, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, zero_division: float = 0, @@ -369,7 +369,7 @@ def _multiclass_stat_scores_update( target: Tensor, num_classes: int, top_k: int = 1, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, ) -> tuple[Tensor, Tensor, Tensor, Tensor]: @@ -450,7 +450,7 @@ def _multiclass_stat_scores_compute( fp: Tensor, tn: Tensor, fn: Tensor, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ) -> Tensor: """Stack statistics and compute support also. @@ -478,7 +478,7 @@ def multiclass_stat_scores( preds: Tensor, target: Tensor, num_classes: int, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", top_k: int = 1, multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, @@ -591,7 +591,7 @@ def multiclass_stat_scores( def _multilabel_stat_scores_arg_validation( num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, zero_division: float = 0, @@ -715,7 +715,7 @@ def _multilabel_stat_scores_compute( fp: Tensor, tn: Tensor, fn: Tensor, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ) -> Tensor: """Stack statistics and compute support also. @@ -742,7 +742,7 @@ def multilabel_stat_scores( target: Tensor, num_labels: int, threshold: float = 0.5, - average: Optional[Literal["micro", "macro", "weighted", "none"]] = "macro", + average: Optional[Literal["micro", "macro", "weighted", "none"]] = "micro", multidim_average: Literal["global", "samplewise"] = "global", ignore_index: Optional[int] = None, validate_args: bool = True,