目录
L1-Loss(MAE)
L o s s ( x , y ) = 1 N ∑ i ( ∣ x i − y i ∣ ) Loss(x,y)=\frac{1}{N} \sum_{i}( |x_i-y_i|) Loss(x,y)=N1i∑(∣xi−yi∣)
简单而言,就是两个向量的绝对值的误差。 默认求平均,可以设置为sum。
也是mean absolute error(MAE)
举例而言:
loss = nn.L1Loss()
'''
L1 Loss
'''
predict_ar = [0,2,3]
target_ar = [2,2,3]
input = torch.FloatTensor(predict_ar)
input.requires_grad = True
target = torch.FloatTensor(target_ar)
output = loss(input, target)
print(output)
结果则是0.667
MSE(L2 Loss)
这个也容易理解,则是平方误差。 mean squared error。
loss = nn.MSELoss()
'''
L1 Loss
'''
predict_ar = [0, 2, 3]
target_ar = [2, 2, 3]
input = torch.FloatTensor(predict_ar)
input.requires_grad = True
target = torch.FloatTensor(target_ar)
output = loss(input, target)
print(output)
这个结果应该是4/3= 1.333
nllloss=negative-log-loss
https://pytorch.org/docs/stable/generated/torch.nn.NLLLoss.html#torch.nn.NLLLoss
The negative log likelihood loss. It is useful to train a classification problem with C classes.
这个loss有点不是非常容易理解,它主要的目标是