Skip to content

Commit 65fecc1

Browse files
sdesrozisIshan-Kumar2
authored andcommitted
doctest for metricslambda (pytorch#2352)
1 parent e222c88 commit 65fecc1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

ignite/metrics/metrics_lambda.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class MetricsLambda(Metric):
2828
else that will be fed to ``f`` as keyword arguments.
2929
3030
Examples:
31-
.. code-block:: python
31+
32+
.. testcode::
3233
3334
precision = Precision(average=False)
3435
recall = Recall(average=False)
@@ -41,6 +42,26 @@ def Fbeta(r, p, beta):
4142
F3 = MetricsLambda(Fbeta, recall, precision, 3)
4243
F4 = MetricsLambda(Fbeta, recall, precision, 4)
4344
45+
F1.attach(default_evaluator, "F1")
46+
F2.attach(default_evaluator, "F2")
47+
F3.attach(default_evaluator, "F3")
48+
F4.attach(default_evaluator, "F4")
49+
50+
y_true = torch.Tensor([1, 0, 1, 0, 0, 1])
51+
y_pred = torch.Tensor([1, 0, 1, 0, 1, 1])
52+
state = default_evaluator.run([[y_pred, y_true]])
53+
print(state.metrics["F1"])
54+
print(state.metrics["F2"])
55+
print(state.metrics["F3"])
56+
print(state.metrics["F4"])
57+
58+
.. testoutput::
59+
60+
0.8571...
61+
0.9375...
62+
0.9677...
63+
0.9807...
64+
4465
When check if the metric is attached, if one of its dependency
4566
metrics is detached, the metric is considered detached too.
4667

0 commit comments

Comments
 (0)