Skip to content

Commit 16bec69

Browse files
author
autoih
committed
doctest example
1 parent fae207a commit 16bec69

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

tensorflow_addons/metrics/cohens_kappa.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,21 @@ class CohenKappa(Metric):
3838
3939
Usage:
4040
41-
```python
42-
actuals = np.array([4, 4, 3, 4, 2, 4, 1, 1], dtype=np.int32)
43-
preds = np.array([4, 4, 3, 4, 4, 2, 1, 1], dtype=np.int32)
44-
weights = np.array([1, 1, 2, 5, 10, 2, 3, 3], dtype=np.int32)
45-
46-
m = tfa.metrics.CohenKappa(num_classes=5)
47-
m.update_state(actuals, preds)
48-
print('Final result: ', m.result().numpy()) # Result: 0.61904764
49-
50-
# To use this with weights, sample_weight argument can be used.
51-
m = tfa.metrics.CohenKappa(num_classes=5)
52-
m.update_state(actuals, preds, sample_weight=weights)
53-
print('Final result: ', m.result().numpy()) # Result: 0.37209308
54-
```
41+
>>> actuals = np.array([4, 4, 3, 4, 2, 4, 1, 1], dtype=np.int32)
42+
>>> preds = np.array([4, 4, 3, 4, 4, 2, 1, 1], dtype=np.int32)
43+
>>> weights = np.array([1, 1, 2, 5, 10, 2, 3, 3], dtype=np.int32)
44+
>>> m = tfa.metrics.CohenKappa(num_classes=5)
45+
>>> m_update = m.update_state(actuals, preds)
46+
>>> m.result()
47+
<tf.Tensor: id=203, shape=(), dtype=float32, numpy=0.61904764>
48+
49+
>>> m = tfa.metrics.CohenKappa(num_classes=5)
50+
>>> m_update = m.update_state(actuals, preds, sample_weight=weights)
51+
>>> m.result()
52+
<tf.Tensor: id=406, shape=(), dtype=float32, numpy=0.37209308>
5553
5654
Usage with tf.keras API:
57-
55+
5856
```python
5957
model = tf.keras.models.Model(inputs, outputs)
6058
model.add_metric(tfa.metrics.CohenKappa(num_classes=5)(outputs))

0 commit comments

Comments
 (0)