Skip to content

Commit b7811d3

Browse files
delzacKeDengMS
authored andcommitted
Fmeasure (microsoft#3343)
* amended a bug, swapped precision and recall * added a bit more documentation
1 parent 2a748e1 commit b7811d3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

bindings/python/cntk/losses/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,10 @@ def fmeasure(output, target, beta=1):
426426
This operation computes the f-measure between the output and target. If beta is set as one,
427427
its called the f1-scorce or dice similarity coefficient. f1-scorce is monotonic in jaccard distance.
428428
429-
f-measure = (1 + bta ** 2) * precision * recall / (beta ** 2 * precision + recall)
429+
f-measure = (1 + beta ** 2) * precision * recall / (beta ** 2 * precision + recall)
430430
431-
This loss function is frequently used in semantic segmentation of images. Works with imbalanced classes too.
431+
This loss function is frequently used in semantic segmentation of images. Works with imbalanced classes, for
432+
balanced classes you should prefer cross_entropy instead.
432433
This operation works with both binary and multiclass classification.
433434
434435
Args:
@@ -450,6 +451,6 @@ def fmeasure(output, target, beta=1):
450451
axis = None
451452

452453
correct_predictions = C.reduce_sum(output * target, axis=axis)
453-
precision = correct_predictions / C.reduce_sum(target, axis=axis)
454-
recall = correct_predictions / C.reduce_sum(output, axis=axis)
454+
precision = correct_predictions / C.reduce_sum(output, axis=axis)
455+
recall = correct_predictions / C.reduce_sum(target, axis=axis)
455456
return 1 - (1 + beta ** 2) * precision * recall / (beta ** 2 * precision + recall)

0 commit comments

Comments
 (0)