当前位置:网站首页>Loss function~
Loss function~
2022-07-02 23:03:00 【Miss chenshen】
Concept :
The loss function is the function used to calculate the difference between the tag value and the predicted value , In the process of machine learning , There are a variety of loss functions to choose from , A typical distance vector , Absolute vector, etc .

The diagram above is a schematic diagram for automatic learning of linear equations . Thick lines are real linear equations , The dotted line is a schematic diagram of the iterative process ,w1 Is the weight of the first iteration ,w2 Is the weight of the second iteration ,w3 Is the weight of the third iteration . As the number of iterations increases , Our goal is to make wn Infinitely close to the real value .
In the figure 1/2/3 The three labels are 3 Predict in the next iteration Y Value and reality Y The difference between values ( The difference here means the loss function , Yes, of course , There are many formulas for calculating the difference in practical application ), The difference here is represented by absolute difference on the diagram . There is also a square difference in multidimensional space , Mean square deviation and other different distance calculation formulas , That is, the loss function .
Common calculation methods of loss function :
1. nn.L1Loss Loss function

L1Loss The calculation method is very simple , Take the average of the absolute error between the predicted value and the real value .
criterion = nn.L1Loss()
loss = criterion(sample, target)
print(loss)
# 1The final output is 1
Calculation logic is as follows :
- First calculate the sum of absolute differences :|0-1|+|1-1|+|2-1|+|3-1| = 4
- And then average :4/4 = 1
2. nn.SmoothL1Loss
SmoothL1Loss Also called Huber Loss, Error in (-1,1) It's the square loss , Other things are L1 Loss .

criterion = nn.SmoothL1Loss()
loss = criterion(sample, target)
print(loss)
# 0.625The final output is 0.625
Calculation logic is as follows :
- First calculate the sum of absolute differences :

- And then average :2.5/4 = 0.625
3. nn.MSELoss
Square loss function . The calculation formula is the average of the sum of squares between the predicted value and the real value .

criterion = nn.MSELoss()
loss = criterion(sample, target)
print(loss)
# 1.5The final output is 1.5
Calculation logic is as follows :
- First calculate the sum of absolute differences :

- And then average :6/4 = 1.5
4. nn.BCELoss
Cross entropy for binary classification , Its calculation formula is complex , Here is mainly a concept , In general, it won't be used .
![loss(o,t) = - \frac{1}{N}\sum_{i=1}^{N}\left [ t_i*log(o_i) + (1-t_i)*log(1-o_i) \right ]](http://img.inotgo.com/imagesLocal/202207/02/202207022103224504_1.gif)
criterion = nn.BCELoss()
loss = criterion(sample, target)
print(loss)
# -13.8155边栏推荐
- mysql重置密码,忘记密码,重置root密码,重置mysql密码
- 高并发介绍及应对
- AES高级加密协议的动机阐述
- [hardware] origin of standard resistance value
- Antd component upload uploads xlsx files and reads the contents of the files
- Local dealers play the community group purchase mode and share millions of operations
- Learning records of data analysis (II) -- simple use of response surface method and design expert
- [Solved] Splunk: Cannot get username when all users are selected“
- LeetCode 968. 监控二叉树
- Go语言sqlx库操作SQLite3数据库增删改查
猜你喜欢
![[NPUCTF2020]ezlogin xPATH注入](/img/6e/dac4dfa0970829775084bada740542.png)
[NPUCTF2020]ezlogin xPATH注入

中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!

Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
![The kth largest element in the [leetcode] array [215]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
The kth largest element in the [leetcode] array [215]

最小生成树 Minimum Spanning Tree
![[Yangcheng cup 2020] easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[Yangcheng cup 2020] easyphp

地平线2022年4月最新方案介绍
![加油站[问题分析->问题转换->贪心]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
加油站[问题分析->问题转换->贪心]
![P7072 [CSP-J2020] 直播获奖](/img/bc/fcbc2b1b9595a3bd31d8577aba9b8b.png)
P7072 [CSP-J2020] 直播获奖

Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
随机推荐
大一学习分享
设置单击右键可以选择用VS Code打开文件
Jerry's charge unplugged, unable to touch the boot [chapter]
Lambda表达式:一篇文章带你通透
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
[leetcode] reverse the word III in the string [557]
China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
Lambda expression: an article takes you through
Jatpack------LiveData
LeetCode 968. Monitor binary tree
The kth largest element in the [leetcode] array [215]
Methods to solve the tampering of Chrome browser and edeg browser homepage
Stop slave is stuck -- the event of the transaction is not copied completely
QT qpprogressbar details
高并发介绍及应对
E-commerce system microservice architecture
go 4種單例模式
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
容器化技术在嵌入式领域的应用
从2022年Q1财报看携程的韧性和远景

