accuracy

您所在的位置:网站首页 paddle评价二分类模型 accuracy

accuracy

2024-06-13 02:34| 来源: 网络整理| 查看: 265

accuracy¶ paddle.metric. accuracy ( input, label, k=1, correct=None, total=None, name=None ) [源代码] ¶

accuracy layer。参考 https://en.wikipedia.org/wiki/Precision_and_recall

使用 input 和 label 计算准确率。如果正确的 label 在 top k 个预测值里,则计算结果加 1。

注解

输出正确率的类型由 input 的类型决定,input 和 label 的类型可以不一样。

参数¶

input (Tensor) - accuracy layer 的输入,即网络的预测值,数据类型为 float32 或 float64 的 Tensor,shape 为 [sample_number, class_dim] 。

label (Tensor) - 数据集的标签,数据类型为 int64 或 int32 的 Tensor,shape 为 [sample_number, 1] 。

k (int,可选) - 取每个类别中 top k 个预测值用于计算,数据类型为 int64 或 int32,默认值为 1。

correct (Tensor,可选) - 正确预测值的个数,数据类型为 int64 或 int32 的 Tensor,默认值为 None。

total (Tensor,可选) - 总共的预测值,数据类型为 int64 或 int32 的 Tensor,默认值为 None。

name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回¶

Tensor,计算出来的正确率,数据类型为 float32 的 Tensor。

代码示例¶ >>> import paddle >>> predictions = paddle.to_tensor([[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], dtype='float32') >>> label = paddle.to_tensor([[2], [0]], dtype="int64") >>> result = paddle.metric.accuracy(input=predictions, label=label, k=1) >>> print(result) Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, 0.50000000) 使用本API的教程文档¶ 使用 VisualDL 可视化模型,数据和训练 模型性能分析(Profiler) 附录: 飞桨框架 2.x 升级指南 升级指南 Tensor 介绍 快速开始-数据并行


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3