Skip to content

Commit e0ac502

Browse files
authored
Merge pull request #132 from ImageMarkup/dice
Add support for Dice coefficient / F1 as a classification target metric
2 parents 1b9c3c4 + 3086100 commit e0ac502

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

isic_challenge_scoring/classification.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ClassificationMetric(enum.Enum):
1717
BALANCED_ACCURACY = 'balanced_accuracy'
1818
AUC = 'auc'
1919
AVERAGE_PRECISION = 'ap'
20+
DICE = 'dice'
2021

2122

2223
@dataclass(init=False)
@@ -100,6 +101,24 @@ def __init__(
100101
]
101102
)
102103
self.validation = per_category_auc.mean()
104+
elif target_metric == ClassificationMetric.DICE:
105+
self.overall = self.macro_average.at['dice']
106+
per_category_dice = pd.Series(
107+
[
108+
metrics.binary_dice(
109+
create_binary_confusion_matrix(
110+
truth_binary_values=truth_probabilities[category].gt(0.5).to_numpy(),
111+
prediction_binary_values=prediction_probabilities[category]
112+
.gt(0.5)
113+
.to_numpy(),
114+
weights=truth_weights['validation_weight'].to_numpy(),
115+
name=category,
116+
)
117+
)
118+
for category in categories
119+
]
120+
)
121+
self.validation = per_category_dice.mean()
103122

104123
@staticmethod
105124
def _category_score(

tests/test_classification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ClassificationMetric.AUC,
1010
ClassificationMetric.BALANCED_ACCURACY,
1111
ClassificationMetric.AVERAGE_PRECISION,
12+
ClassificationMetric.DICE,
1213
],
1314
)
1415
def test_score(classification_truth_file_path, classification_prediction_file_path, target_metric):

0 commit comments

Comments
 (0)