addons
addons copied to clipboard
consistency problem of Tensorflow metrics and tensorflow-addons metric
https://github.com/tensorflow/addons/blob/96136187b14d6508d42bacbf4c619e789ae04078/tensorflow_addons/metrics/f_scores.py#L212-L284
from tensorflow.keras.metrics import Precision, Recall
from tensorflow_addons.metrics import F1Score
metric = F1Score(num_classes=3, threshold=0.5, average='weighted')
y_true = np.array([[1, 1, 1],
[1, 0, 0],
[1, 1, 0]], np.int32)
y_pred = np.array([[0.2, 0.6, 0.7],
[0.2, 0.6, 0.6],
[0.6, 0.8, 0.0]], np.float32)
metric.update_state(y_true, y_pred)
result = metric.result()
result.numpy()
**0.62777776**
p= Precision(thresholds=0.5)
p.update_state(y_true, y_pred)
result = p.result()
result.numpy()
**0.6666667**
r= Recall(thresholds=0.5)
r.update_state(y_true, y_pred)
result = r.result()
result.numpy()
**0.6666667**
f1 = 2*(p*r)/(p+r) = 0.6666667 # 0.62777776