当前位置:网站首页>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边栏推荐
- Go语言sqlx库操作SQLite3数据库增删改查
- 悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
- 数据分析学习记录--用EXCEL完成简单的单因素方差分析
- Golang interview finishing three resumes how to write
- Generics and reflection, this is enough
- Golang面试整理 三 简历如何书写
- China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
- Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
- [chestnut sugar GIS] ArcScene - how to make elevation map with height
- stop slave卡住--事务的事件没有复制完整
猜你喜欢

最小生成树 Minimum Spanning Tree

Kubernetes uses the host name to allocate the pod on the specified node

地平线2022年4月最新方案介绍

Data analysis learning records -- complete a simple one-way ANOVA with Excel

STM32之ADC

海思3559万能平台搭建:在截获的YUV图像上画框

WebRTC音视频采集和播放示例及MediaStream媒体流解析

Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly

Jatpack------LiveData

Successfully changed Splunk default URL root path
随机推荐
最小生成树 Minimum Spanning Tree
[chestnut sugar GIS] ArcScene - how to make elevation map with height
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
[Yangcheng cup 2020] easyphp
數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
Kubernetes uses the host name to allocate the pod on the specified node
設置單擊右鍵可以選擇用VS Code打開文件
Antd component upload uploads xlsx files and reads the contents of the files
MySQL查询附近的数据.并按距离进行排序.
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
P7072 [CSP-J2020] 直播获奖
数据分析学习记录--用EXCEL完成简单的单因素方差分析
Gas station [problem analysis - > problem conversion - > greed]
从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Go multithreaded data search
Local dealers play the community group purchase mode and share millions of operations
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
Qt QScrollArea
悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖

