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

基础组件学习——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}
accuracyEvaluationModule(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.mzph.cn/news/619000.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

RK3568驱动指南|第十二篇 GPIO子系统-第135章 GPIO子系统与pinctrl子系统相结合实验

瑞芯微RK3568芯片是一款定位中高端的通用型SOC&#xff0c;采用22nm制程工艺&#xff0c;搭载一颗四核Cortex-A55处理器和Mali G52 2EE 图形处理器。RK3568 支持4K 解码和 1080P 编码&#xff0c;支持SATA/PCIE/USB3.0 外围接口。RK3568内置独立NPU&#xff0c;可用于轻量级人工…

解决ELK日志收集中Logstash报错的关键步

ElK执行日志收集的时候logstash报错&#xff1a; Failed to execute action {:action>LogStash::PipelineAction::Create/pipeline_id:main, :exception>“LogStash::ConfigurationError”, :message>“Expected one of [^\r\n], “\r”, “\n” at line 88, column 4…

ChromeDriver 添加到系统PATH

在软件测试和自动化脚本中&#xff0c;ChromeDriver是一个不可或缺的工具。为了方便使用&#xff0c;将其添加到系统PATH中是一个明智的选择。以下是在Windows、macOS或Linux上完成此任务的详细步骤。 在 Windows 上&#xff1a; 下载并保存 ChromeDriver&#xff1a; 访问Chro…

医院患者满意度调查方案

制定医院患者满意度调查方案是确保调查的有效性和有针对性的关键步骤。以下是一些编制医院患者满意度调查方案的关键步骤和考虑因素&#xff1a; 1. 确定调查目标&#xff1a; 首先&#xff0c;明确调查的主要目标。你希望了解哪些方面的患者满意度&#xff1f;这可能包括医疗…

openEuler安装Docker艰辛路程

文章目录 安装docker测试docker关于windows docker拉取镜像查看所有镜像删除镜像删除不在运行的进程强制删除正在运行的进程 启动docker容器服务-d测试 停止docker容器服务查看docker启动进程更新容器(没有自启动功能&#xff0c;更新为自启动)docker端口映射进入容器修改内容退…

flume

第 1 章 Flume 概述 1.1 Flume 定义 Flume 是 Cloudera 提供的一个高可用的&#xff0c;高可靠的&#xff0c;分布式的 海量日志采集、聚合和传 输的系统 。 Flume 基于流式架构&#xff0c;灵活简单。 为什么选用 Flume Python 爬虫数据 Java 后台日志数据 服…

Unity AssetBundles资源管理和热更新

项目中的做法&#xff0c;在项目中一般会把资源按照文件目录去划分资源&#xff0c;以文件路径的名字作为AB的名字&#xff0c;一般都是把资源的这些放到预处理中。 一般会分为几个类型&#xff0c;比如把单个文件夹下的每个资源进行打bundle&#xff0c;把单个文件夹下的所有资…

新手练习项目 5:简易计算器(C++)

名人说&#xff1a;莫听穿林打叶声&#xff0c;何妨吟啸且徐行。—— 苏轼《定风波莫听穿林打叶声》 Code_流苏(CSDN)&#xff08;一个喜欢古诗词和编程的Coder&#xff09; 目录 一、效果图二、代码&#xff08;带注释&#xff09;三、说明 一、效果图 二、代码&#xff08;带…

HTML--图片

HTML中使用 img标签来显示一张图片 它有三个属性&#xff1a; src alt tiltle src属性&#xff1a; 图片路径建议为相对路径&#xff0c;以免文件移动造成无法正常工作 用法&#xff1a; <img src"图片路径和名字"><!DOCTYPE html> <html> <…

QWebEngineView类方法、属性、信号与槽汇总

文章目录 📖 介绍 📖🏡 环境 🏡📒 使用方法 📒📝 使用示例📝 方法📝 属性📝 信号(Signals)📝 槽(Slots)⚓️ 相关链接 ⚓️📖 介绍 📖 QWebEngineView 是 Qt 提供的一个用于呈现 Web 内容的类,基于 Google 的 Chromium 浏览器引擎。它提供了对现…

算法训练day12Leetcode239滑动窗口最大值347前k个高频元素

今日学习文章链接 https://programmercarl.com/0347.%E5%89%8DK%E4%B8%AA%E9%AB%98%E9%A2%91%E5%85%83%E7%B4%A0.html#%E6%80%9D%E8%B7%AF 239 滑动窗口最大值 题目描述 给你一个整数数组 nums&#xff0c;有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只…

小程序自定义添加active类的方法

class"todayBtn {{today true ? btn_isactive : }}"

VCG 拷贝与合并Mesh网格

文章目录 一、简介二、实现代码三、实现效果参考资料一、简介 考虑到网格本身的复杂性质,VCG中是严格禁止任何将网格复制为简单对象的尝试;要复制一个网格或者合并两个网格对象,你必须使用Append类。 二、实现代码 合并网格 //VCG #include <vcg/complex/algorithms/crea…

Mac M1 Parallels CentOS7.9 Install Jenkins

官网: https://www.jenkins.io/ 一、Install & Check Java Env Oracle官网下载Java: https://www.oracle.com/cn/ # 拷贝到Jenkins服务器 scp Downloads/jdk-8u391-linux-aarch64.tar.gz root10.211.55.34:~# 解压 mkdir -p /opt/java && tar -zxvf jdk-8u391-li…

电脑上不安装Oracle,但是虚拟机装了Oracle,怎么连接到虚拟机里的Oracle数据库呢?

1、准备工作 1.1、确定数据库版本信息 注&#xff1a;如果知道数据库的版本信息&#xff0c;这个步骤可以跳过。 比较简单的方法&#xff0c;直接看数据库的安装位置&#xff0c;也就是数字&#xff08;但是这个方法确定就是&#xff0c;不好确定是多少位的数据库&#xff09;…

二叉树算法思想和原理:介绍通过递归算法计算二叉树结点个数的基本思路及C#、C++代码示例

二叉树是一种非常常见的数据结构&#xff0c;它由结点组成&#xff0c;每个结点最多有两个子结点&#xff0c;分别称为左子结点和右子结点。在二叉树中&#xff0c;每个结点都有一个数据域和一个指针域&#xff0c;指针域分别指向左子结点和右子结点。二叉树有很多种不同的类型…

【Flask】使用 werkzeug 安全地处理密码

使用 werkzeug 安全地处理密码 假设我们要实现一个登录注册的功能&#xff0c;最简单的方式是先创建一个表&#xff0c;有 username 和 password 字段&#xff0c;然后再编写相应的登录和注册接口。 创建表 以下是一个简单的例子&#xff0c;展示了如何创建一个用户表并定义…

day07

1.return关键字的用法return 在有返回值的方法中使用return 返回值;return 关键字书写以后后面的代码就不能写了2.声明方法的四种形式无参无返回值的语法格式有参无返回值的无参有返回值的有参有返回值的3.什么是形参&#xff0c;什么是实参在方法的声明处&#xff0c;写的变量…

年日历实现, 2、维护工作日和休息日, 3、初始化法定节假日

you:请帮我用vue2实现如下功能&#xff1a;1、年日历实现&#xff0c; 2、维护工作日和休息日&#xff0c; 3、初始化法定节假日 当你想要使用Vue.js 2实现年度日历&#xff0c;并维护工作日和休息日以及初始化法定节假日时&#xff0c;你可以考虑以下步骤。 首先&#xff0c…

全志图形引擎 以 F1C200s 为例介绍

全志图形引擎的思路在很多自家芯片上是大差不差的。这些芯片包括但不限于:F1C100s、F1C200s、V3S、A64、T113、H8、H3、A83。 F1C200s 和 F1C100s 相差极小,仅集成内存大小有所差别。 下面以 F1C200s 为例讲解全志图形引擎。 F1C200s的显示系统由以下四部分组成: 时序控制…