python - Tensorflow 指标和 tensorflow-addons 指标的一致性问题
问题描述
这是计算精度的示例,在 tensorflow.keras.metrics 中实现的召回率和在 tensorflow_addons.metrics 中实现的 F1_score。结果显然不一致!
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
解决方案
推荐阅读
- java - 偶数位置的Java数组产品
- php - 列出未添加到购物车的产品
- python - python - 如何通过pool.imap()函数传递数据以外的参数以在python中进行多处理?
- json - 监控 JSON 或 YAML 配置文件并显示更改属性的父级
- node.js - Nestjs 中间件不会抛出任何错误
- python-asyncio - Python asyncio,aiohttp:动态更新任务循环应该工作直到特定条件
- python - open3d计算网格和点云之间的距离
- java - 为什么在 Xuggle 中对样本数组进行编码后,我的音频文件如此不稳定?
- excel - Powershell Excel 自动化复制粘贴 - ImportExcel 模块
- automation - svg 按钮单击并复制 url 涉及的步骤是什么