【HuggingFace Transformer库学习笔记】基础组件学习:Evaluate

news/2024/7/19 10:39:13 标签: transformer, 学习, 笔记

基础组件学习——Evaluate

在这里插入图片描述
在这里插入图片描述

Evaluate使用指南

查看支持的评估函数

# include_community:是否添加社区实现的部分
# with_details:是否展示更多细节
evaluate.list_evaluation_modules(include_community=False, with_details=True)

加载评估函数

accuracy = evaluate.load("accuracy")

查看评估函数说明

print(accuracy.description)


Accuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
 Where:
TP: True positive
TN: True negative
FP: False positive
FN: False negative

查看示例说明

print(accuracy.inputs_description)

Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
    sample_weight (`list` of `float`): Sample weights Defaults to None.

Returns:
    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.

Examples:

    Example 1-A simple example
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
        >>> print(results)
        {'accuracy': 0.5}

    Example 2-The same as Example 1, except with `normalize` set to `False`.
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)
        >>> print(results)
        {'accuracy': 3.0}

    Example 3-The same as Example 1, except with `sample_weight` set.
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])
        >>> print(results)
        {'accuracy': 0.8778625954198473}
accuracy

EvaluationModule(name: "accuracy", module_type: "metric", features: {'predictions': Value(dtype='int32', id=None), 'references': Value(dtype='int32', id=None)}, usage: """
Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
    sample_weight (`list` of `float`): Sample weights Defaults to None.

Returns:
    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.

Examples:

    Example 1-A simple example
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
        >>> print(results)
        {'accuracy': 0.5}

    Example 2-The same as Example 1, except with `normalize` set to `False`.
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)
        >>> print(results)
        {'accuracy': 3.0}

    Example 3-The same as Example 1, except with `sample_weight` set.
        >>> accuracy_metric = evaluate.load("accuracy")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])
        >>> print(results)
        {'accuracy': 0.8778625954198473}
""", stored examples: 0)

评估指标计算——全局计算

accuracy = evaluate.load("accuracy")
results = accuracy.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
results

{'accuracy': 0.5}

评估指标计算——迭代计算

# 一个一个传
accuracy = evaluate.load("accuracy")
for ref, pred in zip([0,1,0,1], [1,0,0,1]):
    accuracy.add(references=ref, predictions=pred)
accuracy.compute()

{'accuracy': 0.5}
# 一批一批传
accuracy = evaluate.load("accuracy")
for refs, preds in zip([[0,1],[0,1]], [[1,0],[0,1]]):
    accuracy.add_batch(references=refs, predictions=preds)
accuracy.compute()

{'accuracy': 0.5}

多个评估指标计算

clf_metrics = evaluate.combine(["accuracy", "f1", "recall", "precision"])
clf_metrics

<evaluate.module.CombinedEvaluations at 0x1e92e72f880>
clf_metrics.compute(predictions=[0, 1, 0], references=[0, 1, 1])

{'accuracy': 0.6666666666666666,
 'f1': 0.6666666666666666,
 'recall': 0.5,
 'precision': 1.0}

评估结果对比可视化

from evaluate.visualization import radar_plot   # 目前只支持雷达图

data = [
   {"accuracy": 0.99, "precision": 0.8, "f1": 0.95, "latency_in_seconds": 33.6},
   {"accuracy": 0.98, "precision": 0.87, "f1": 0.91, "latency_in_seconds": 11.2},
   {"accuracy": 0.98, "precision": 0.78, "f1": 0.88, "latency_in_seconds": 87.6}, 
   {"accuracy": 0.88, "precision": 0.78, "f1": 0.81, "latency_in_seconds": 101.6}
   ]
model_names = ["Model 1", "Model 2", "Model 3", "Model 4"]

plot = radar_plot(data=data, model_names=model_names)

在这里插入图片描述


http://www.niftyadmin.cn/n/5321654.html

相关文章

万界星空科技家具制造业MES系统解决方案

家具行业专业化生产和信息化管理程度较低。随着企业规模的迅速扩大&#xff0c;家具行业中用现有的凭手工发放图纸、制作bom、发放工艺说明文件越来越难以适应现代家具行业、已经成为家具行业快速发展的瓶颈。必须通过实施万界星空科技MES生产管理软件&#xff0c;实现部门之间…

ROS无人机开发常见错误

飞控部分 一、解锁时飞控不闪红灯&#xff0c;无任何反应&#xff0c;地面站也无报错 解决办法&#xff1a; 打开地面站的遥控器一栏 首先检查右下角Channel Monitor是否有识别出遥控各通道的值&#xff0c;如果没有&#xff0c;检查遥控器是否打开&#xff0c;遥控器和接收…

并发List源码剖析

并发包中的并发List只有CopyOnWriteArrayList。 CopyOnWriteArrayList是一个线程安全的ArrayList,对其进行的修改操作都是在底层的一个复制的数组(快照)上进行的&#xff0c;也就是使用了写时复制策略。 在CopyOnWriteArrayList的类图中&#xff0c;每个CopyOnWriteArrayList对…

Python-第一阶段-第三章 判断语句

目录 一、布尔类型和比较运算符 二、if 语句的基本格式 ​编辑 三、if-else语句 四、if elif else语句 五、判断语句的嵌套 进行逻辑判断&#xff0c;是生活中常见的行为。同样&#xff0c;在程序中&#xff0c;进行逻辑判断也是最为基础的功能。 一、布尔类型和比较运算…

Mybatis的一些问答记录

0、delegate属性即装饰器,调用cache中的任意一个方法都会沿着链条往下依次执行。 1、JDBC的PreparedStatement(一次编译多次执行)每执行一次executeQuery()就会清空上一次的参数&#xff0c;执行完executeQuery()后就可以获取结果。 ReuseExecutor可重用执行器可以指定使用JDB…

从零到一保姆级深度学习Docker镜像配置教程

文章目录 前言一、Docker相关工具安装1.1 Docker安装和配置1.2 Nvidia-Docker安装1.3 Docker-Compose安装 二、深度学习环境Docker镜像配置2.1 基础镜像拉取与启动2.2 深度学习Docker环境配置2.2.1 更换软件源2.2.2 安装常见命令2.2.3 安装SSH2.2.4 安装Miniconda2.2.5 安装Pyt…

linux建立软链接——以matlab为例

如果软件没有建立软连接&#xff0c;每次打开terminal就只是个黑黑的窗口&#xff0c;每次打开软件都要自己load一次&#xff0c;比较麻烦。 第一步&#xff1a; 在工作夹新建文档&#xff1a;project.cshrc 第二步&#xff1a; 在夹新建文档中写入&#xff1a;module laod m…

计算机毕设项目(二)基于django+vue+sqlite实现自适应学习系统,在线考试系统

文章目录 自适应学习系统功能介绍分权分域用户管理考试与练习管理练习记录管理学习内容管理其他功能管理界面部分源码展示完整代码 自适应学习系统功能介绍 这个系统是一个基于Django框架的Python在线考试和学习平台。vuedjango在线学习系统&#xff0c;在线考试系统。数据库使…