Skip to content

Commit

Permalink
Merge pull request #132 from ImageMarkup/dice
Browse files Browse the repository at this point in the history
Add support for Dice coefficient / F1 as a classification target metric
  • Loading branch information
brianhelba authored Feb 4, 2025
2 parents 1b9c3c4 + 3086100 commit e0ac502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions isic_challenge_scoring/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ClassificationMetric(enum.Enum):
BALANCED_ACCURACY = 'balanced_accuracy'
AUC = 'auc'
AVERAGE_PRECISION = 'ap'
DICE = 'dice'


@dataclass(init=False)
Expand Down Expand Up @@ -100,6 +101,24 @@ def __init__(
]
)
self.validation = per_category_auc.mean()
elif target_metric == ClassificationMetric.DICE:
self.overall = self.macro_average.at['dice']
per_category_dice = pd.Series(
[
metrics.binary_dice(
create_binary_confusion_matrix(
truth_binary_values=truth_probabilities[category].gt(0.5).to_numpy(),
prediction_binary_values=prediction_probabilities[category]
.gt(0.5)
.to_numpy(),
weights=truth_weights['validation_weight'].to_numpy(),
name=category,
)
)
for category in categories
]
)
self.validation = per_category_dice.mean()

@staticmethod
def _category_score(
Expand Down
1 change: 1 addition & 0 deletions tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ClassificationMetric.AUC,
ClassificationMetric.BALANCED_ACCURACY,
ClassificationMetric.AVERAGE_PRECISION,
ClassificationMetric.DICE,
],
)
def test_score(classification_truth_file_path, classification_prediction_file_path, target_metric):
Expand Down

0 comments on commit e0ac502

Please sign in to comment.