Skip to content

Commit ecfff55

Browse files
sdesrozisIshan-Kumar2
authored andcommitted
[skip ci] add doctest for CohenKappa metric (pytorch#2321)
1 parent aeda534 commit ecfff55

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ def run(self):
340340
from ignite.metrics import *
341341
from ignite.utils import *
342342
343+
from ignite.contrib.metrics import *
344+
343345
manual_seed(666)
344346
345347
# create default evaluator for doctests

ignite/contrib/metrics/cohen_kappa.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,24 @@ class CohenKappa(EpochMetric):
2424
no issues. User will be warned in case there are any issues computing the function.
2525
device: optional device specification for internal storage.
2626
27-
.. code-block:: python
27+
Examples:
28+
To use with ``Engine`` and ``process_function``, simply attach the metric instance to the engine.
29+
The output of the engine's ``process_function`` needs to be in the format of
30+
``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y, ...}``. If not, ``output_tranform`` can be added
31+
to the metric to transform the output into the form expected by the metric.
2832
29-
def activated_output_transform(output):
30-
y_pred, y = output
31-
return y_pred, y
33+
.. testcode::
3234
33-
weights = None or linear or quadratic
35+
metric = CohenKappa()
36+
metric.attach(default_evaluator, 'ck')
37+
y_true = torch.Tensor([2, 0, 2, 2, 0, 1])
38+
y_pred = torch.Tensor([0, 0, 2, 2, 0, 2])
39+
state = default_evaluator.run([[y_pred, y_true]])
40+
print(state.metrics['ck'])
3441
35-
cohen_kappa = CohenKappa(activated_output_transform, weights)
42+
.. testoutput::
43+
44+
0.4285...
3645
3746
"""
3847

0 commit comments

Comments
 (0)