DOC Add multilabel example for precision, recall and F1
@@ -1093,6 +1093,11 @@ def f1_score(
>>> y_pred = [0, 0, 0, 0, 0, 0]
>>> f1_score(y_true, y_pred, zero_division=1)
1.0...
+ >>> # multilabel classification
+ >>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]
+ >>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]
+ >>> f1_score(y_true, y_pred, average=None)
+ array([0.66666667, 1. , 0.66666667])
Notes
-----
@@ -1721,7 +1726,11 @@ def precision_score(
array([0.33..., 0. , 0. ])
>>> precision_score(y_true, y_pred, average=None, zero_division=1)
array([0.33..., 1. , 1. ])
-
+ >>> # multilabel classification
+ >>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]
+ >>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]
+ >>> precision_score(y_true, y_pred, average=None)
+ array([0.5, 1. , 1. ])
"""
p, _, _, _ = precision_recall_fscore_support(
y_true,
@@ -1851,6 +1860,11 @@ def recall_score(
array([0.5, 0. , 0. ])
>>> recall_score(y_true, y_pred, average=None, zero_division=1)
array([0.5, 1. , 1. ])
+ >>> # multilabel classification
+ >>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]
+ >>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]
+ >>> recall_score(y_true, y_pred, average=None)
+ array([1. , 1. , 0.5])
"""
_, r, _, _ = precision_recall_fscore_support(
y_true,
