当前位置:网站首页>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)
# 1
The 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.625
The 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.5
The 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 .
criterion = nn.BCELoss()
loss = criterion(sample, target)
print(loss)
# -13.8155
边栏推荐
- MySQL reset password, forget password, reset root password, reset MySQL password
- Value sequence < detailed explanation of daily question >
- Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
- go 4种单例模式
- Higher order operation of bits
- Easyclick, EC Quanlang network verification source code
- `Usage of ${}`
- Successfully changed Splunk default URL root path
- LeetCode 968. 监控二叉树
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
猜你喜欢
【喜欢的诗词】好了歌
Niuke network: maximum submatrix
The kth largest element in the [leetcode] array [215]
Go language sqlx library operation SQLite3 database addition, deletion, modification and query
Qt QSplitter拆分器
Qt QScrollArea
Qt QProgressBar详解
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
设置单击右键可以选择用VS Code打开文件
随机推荐
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Antd component upload uploads xlsx files and reads the contents of the files
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
Mask R-CNN
stop slave卡住--事务的事件没有复制完整
Motivation du Protocole de chiffrement avancé AES
[npuctf2020]ezlogin XPath injection
Looking at Ctrip's toughness and vision from the Q1 financial report in 2022
Niuke network: maximum submatrix
归并排序详解及应用
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
[leetcode] reverse string [344]
WebRTC音视频采集和播放示例及MediaStream媒体流解析
The motivation of AES Advanced Encryption Protocol
Learning Websites commonly used by circuit designers
Easyclick, EC Quanlang network verification source code
20220527_数据库过程_语句留档
Mask R-CNN
编辑卡顿
P1007 独木桥