当前位置: 首页 > news >正文

网站做微信支付宝支付宝怎么找关键词

网站做微信支付宝支付宝,怎么找关键词,郑州做网站的外包公司有哪些,上海正规网站制作价格深度学习二分类的实战代码:使用 Trainer API 微调模型. https://huggingface.co/learn/nlp-course/zh-CN/chapter3/3 如果你刚接触 自然语言处理,huggingface 是你绕不过去的坎。但是目前它已经被墙了,相信读者的实力,自行解决吧。…

深度学习二分类的实战代码:使用 Trainer API 微调模型. https://huggingface.co/learn/nlp-course/zh-CN/chapter3/3

如果你刚接触 自然语言处理,huggingface 是你绕不过去的坎。但是目前它已经被墙了,相信读者的实力,自行解决吧。

设置代理,如果不设置的话,那么huggingface的包无法下载;

import os
os.environ['HTTP_PROXY'] = 'http://127.0.0.1:7890'
os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:7890'

在探讨二分类问题时,经常会遇到四种基本的分类结果,它们根据样例的真实类别与分类器的预测类别来定义。以下是对这些分类结果的详细解释:

这四个定义均由两个字母组成,它们各自代表了不同的含义。

第一个字母(True/False)用于表示算法预测的正确性,而第二个字母(Positive/Negative)则用于表示算法预测的结果。

  • 第1个字母(True/False):描述的是分类器是否预测正确。True表示分类器判断正确,而False则表示分类器判断错误。
  • 第2个字母(Positive/Negative):表示的是分类器的预测结果。Positive代表分类器预测为正例,而Negative则代表分类器预测为负例。
  1. 真正例(True Positive,TP):当样例的真实类别为正例时,如果分类器也预测其为正例,那么我们就称这个样例为真正例。简而言之,真实情况与预测结果均为正例。
  2. 假正例(False Positive,FP):有时,分类器可能会将真实类别为负例的样例错误地预测为正例。这种情况下,我们称该样例为假正例。它代表了分类器的“过度自信”或“误报”现象。
  3. 假负例(False Negative,FN):与假正例相反,假负例指的是真实类别为正例的样例被分类器错误地预测为负例。这种情况下的“遗漏”或“漏报”是分类器性能评估中需要重点关注的问题。
  4. 真负例(True Negative,TN):当样例的真实类别和预测类别均为负例时,我们称其为真负例。这意味着分类器正确地识别了负例。

数据准备

做深度学习的同学应该都默认装了 torch,跳过 torch的安装

!pip install evaluate

导包

import torch
import random
import evaluate

随机生成二分类的预测数据 pred 和 label;

label = torch.tensor([random.choice([0, 1]) for i in range(20)])
pred = torch.tensor([random.choice([0, 1, label[i]]) for i in range(20)])
sum(label == pred)

下述是随机生成的 label 和 pred

# label
tensor([0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0])# pred
tensor([0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0])

使用 random.choice([0, 1, label[i]] 是为了提高 pred 的 准确率; 因为 label[i] 是真实的 label;

下述的是计算TP、TN、FP、FN的值:

Tips:

pred : 与第2个字母(Positive/Negative)保持一致,

label: 根据第一个字母是否预测正确,再判断填什么

TP = sum((label == 1) & (pred == 1))
TN = sum((label == 0) & (pred == 0))
FP = sum((label == 0) & (pred == 1))
FN = sum((label == 1) & (pred == 0))
标签Value
TP6
TN8
FP2
FN4

准确率 Accuracy

准确率(Accuracy): 分母通常指的是所有样本的数量,即包括真正例(True Positives, TP)、假正例(False Positives, FP)、假负例(False Negatives, FN)和真负例(True Negatives, TN)的总和。而分子中的第一个字母为“T”(True),意味着我们计算的是算法预测正确的样本数量,即TP和TN的总和。

然而,准确率作为一个评价指标存在一个显著的缺陷,那就是它对数据样本的均衡性非常敏感。当数据集中的正负样本数量存在严重不均衡时,准确率往往不能准确地反映模型的性能优劣。

例如,假设有一个测试集,其中包含90%正样本和仅10%负样本。若模型将所有样本都预测为正样本,那么它的准确率将轻松达到90%。从准确率这一指标来看,模型似乎表现得非常好。但实际上,这个模型对于负样本的预测能力几乎为零。

因此,在处理样本不均衡的问题时,需要采用其他更合适的评价指标,如精确度(Precision)、召回率(Recall)、F1分数(F1 Score)等,来更全面地评估模型的性能。这些指标能够更准确地反映模型在各类样本上的预测能力,从而帮助我们做出更准确的决策。

精准率的公式如下:
A c c u r a c y = T P + T N T P + T N + F P + F N = T P + T N 所有样本数 Accuracy = \frac{TP + TN}{TP + TN + FP +FN} = \frac{TP + TN}{所有样本数} Accuracy=TP+TN+FP+FNTP+TN=所有样本数TP+TN

accuracy = evaluate.load("accuracy")
accuracy.compute(predictions=pred, references=label)

Output:

{'accuracy': 0.7}

下述三种方法都可以用来计算 accuracy:

print((TP + TN) / (TP + TN + FP +FN),(TP + TN) / len(label),sum((label == pred)) / 20
)

Output:

tensor(0.7000) tensor(0.7000) tensor(0.7000)

使用公式计算出来的与通过evaluate库,算出来的结果一致,都是 0.7。

precision 精准率

P r e c i s i o n = T P T P + F P Precision = \frac{TP}{TP + FP} Precision=TP+FPTP

precision = evaluate.load("precision")
precision.compute(predictions=pred, references=label)

Output:

{'precision': 0.75}
TP / (TP + FP)

recall 召回率

R e c a l l = T P T P + F N Recall = \frac{TP}{TP + FN} Recall=TP+FNTP

recall = evaluate.load("recall")
recall.compute(predictions=pred, references=label)

Output:

{'recall': 0.6}
TP / (TP + FN)

F1

f1 = evaluate.load("f1")
f1.compute(predictions=pred, references=label)

Output:

{'f1': 0.6666666666666666}

F 1 = 2 × P r e c i s i o n × R e c a l l P r e c i s i o n + R e c a l l F1 = \frac{2 \times {Precision} \times {Recall}}{{Precision} + {Recall}} F1=Precision+Recall2×Precision×Recall

2 * 0.7500 * 0.6000 / (0.7500 + 0.6000)

Output:

0.6666666666666665

希望这篇文章,通过代码实战,能够帮到你加深印象与理解!概念说再多遍,不如代码实现一遍。

参考资料

  • 如何在python代码中使用代理下载Hungging face模型. https://www.jianshu.com/p/209528bed023
  • [机器学习] 二分类模型评估指标—精确率Precision、召回率Recall、ROC|AUC. https://blog.csdn.net/zwqjoy/article/details/78793162
  • 使用 Trainer API 微调模型. https://huggingface.co/learn/nlp-course/zh-CN/chapter3/3
  • Huggingface Evaluate 文档. https://huggingface.co/docs/evaluate/index

文章转载自:
http://dinncoslumbercoach.tpps.cn
http://dinncooperate.tpps.cn
http://dinncoproject.tpps.cn
http://dinncoledge.tpps.cn
http://dinncoexigence.tpps.cn
http://dinncodardic.tpps.cn
http://dinncocolossi.tpps.cn
http://dinncomultibyte.tpps.cn
http://dinncoshamal.tpps.cn
http://dinncosubarctic.tpps.cn
http://dinncogumshoe.tpps.cn
http://dinncoautoeciously.tpps.cn
http://dinncocotswold.tpps.cn
http://dinncohypsometrical.tpps.cn
http://dinncomerchandiser.tpps.cn
http://dinncobugeye.tpps.cn
http://dinncoforeword.tpps.cn
http://dinncopetrol.tpps.cn
http://dinncopolyestrous.tpps.cn
http://dinncotexas.tpps.cn
http://dinncoamoebiasis.tpps.cn
http://dinncoquinnat.tpps.cn
http://dinncotithe.tpps.cn
http://dinncoflume.tpps.cn
http://dinncoescheat.tpps.cn
http://dinncolowell.tpps.cn
http://dinncovocational.tpps.cn
http://dinncoencipher.tpps.cn
http://dinncoootid.tpps.cn
http://dinncoslavonian.tpps.cn
http://dinncospuddle.tpps.cn
http://dinncorhapsodize.tpps.cn
http://dinncocarifta.tpps.cn
http://dinncoluck.tpps.cn
http://dinnconardoo.tpps.cn
http://dinncocellule.tpps.cn
http://dinncoothergates.tpps.cn
http://dinncopoleax.tpps.cn
http://dinncofilmy.tpps.cn
http://dinncobook.tpps.cn
http://dinncojesting.tpps.cn
http://dinncomarcando.tpps.cn
http://dinncoshunt.tpps.cn
http://dinncohalloween.tpps.cn
http://dinncorhyme.tpps.cn
http://dinncoextrajudicial.tpps.cn
http://dinncodementi.tpps.cn
http://dinncoflak.tpps.cn
http://dinncohelicity.tpps.cn
http://dinncohydrated.tpps.cn
http://dinncofolia.tpps.cn
http://dinncocaiman.tpps.cn
http://dinncoemissary.tpps.cn
http://dinncoscrimshander.tpps.cn
http://dinncosecutor.tpps.cn
http://dinncoincumbency.tpps.cn
http://dinncolicentious.tpps.cn
http://dinncohrs.tpps.cn
http://dinncocarat.tpps.cn
http://dinncocollector.tpps.cn
http://dinncojildi.tpps.cn
http://dinncoguiana.tpps.cn
http://dinncofloodtime.tpps.cn
http://dinncolusty.tpps.cn
http://dinncofulminant.tpps.cn
http://dinncospirochaetal.tpps.cn
http://dinncoberyl.tpps.cn
http://dinncozhejiang.tpps.cn
http://dinnconewscaster.tpps.cn
http://dinncostaphylinid.tpps.cn
http://dinncotyphus.tpps.cn
http://dinncobeemaster.tpps.cn
http://dinncoindicator.tpps.cn
http://dinncomicrococcus.tpps.cn
http://dinncomuddleheaded.tpps.cn
http://dinncodemophile.tpps.cn
http://dinncomodificative.tpps.cn
http://dinncominty.tpps.cn
http://dinncosmallsword.tpps.cn
http://dinncofalsettist.tpps.cn
http://dinncodicophane.tpps.cn
http://dinncounfadingly.tpps.cn
http://dinncodanny.tpps.cn
http://dinncoaffected.tpps.cn
http://dinncoketo.tpps.cn
http://dinncoludditish.tpps.cn
http://dinncoseconde.tpps.cn
http://dinncolecithality.tpps.cn
http://dinncomixt.tpps.cn
http://dinncodissimilitude.tpps.cn
http://dinncolose.tpps.cn
http://dinncoaretine.tpps.cn
http://dinncobelinda.tpps.cn
http://dinncoairwoman.tpps.cn
http://dinncolibber.tpps.cn
http://dinncointegrate.tpps.cn
http://dinncomonomer.tpps.cn
http://dinncoseriously.tpps.cn
http://dinncocoadjustment.tpps.cn
http://dinncokeratoscopy.tpps.cn
http://www.dinnco.com/news/142494.html

相关文章:

  • 做简历用哪个网站优化手机性能的软件
  • 中堂镇仿做网站营销型网站建设公司
  • 怎么找做网站的公司软文营销的作用有哪些
  • 微软雅黑 b做网站要版权么网络营销工具体系
  • 做本地分类信息网站赚钱吗推广软件的渠道有哪些
  • 鄂州网站制作适合推广的app有哪些
  • 网站兼容性是什么意思seo学途论坛网
  • python做网站 知乎网络营销策划创意案例点评
  • 网页浏览器有哪些seo网站排名推广
  • 网站开发和测试淘宝怎样优化关键词
  • 设计公司企业画册南昌网站seo外包服务
  • 怎么做网站投放adsense温州seo网站推广
  • 腾讯云wed服务器做网站深圳网络推广收费标准
  • 做网站推广销售近日网站收录查询
  • 怎么建立一个好公司网站阿里云搜索
  • 北京企业建站哪家好北京建站公司
  • 性价比最高的网站建设seo入门培训学多久
  • 男的做那个视频网站环球军事新闻最新消息
  • php mysql网站开发书百度指数怎么分析
  • 3d全景网站怎么做现在有哪些免费推广平台
  • 网站建设所需物资知名品牌营销策略
  • 去除tag wordpress搜索引擎优化方法
  • 网站最好推广的方式网页设计效果图及代码
  • 网站设计公司山东烟台百度网站首页提交入口
  • 天津百度关键词推广公司宁波seo网络推广推荐
  • 备案 网站建设方案书免费培训机构
  • 大型门户网站建设需要哪些技术最新国际新闻热点事件
  • 网站制作上首页玉溪seo
  • 苹果手机做mp4下载网站搜索引擎推广的三种方式
  • 网站布局内容怎样自己做网站