当前位置:   article > 正文

均方误差损失函数(MSE,mean squared error)_mean_squared_error

mean_squared_error

推荐一下:深度学习AI-计算机视觉(CV)-整体解决方案课件(Yolo+Flask+Vue+Waitress+Nginx)

视频教程:https://www.bilibili.com/video/BV19h4y1874T/?spm_id_from=333.999.0.0

均方误差损失函数(MSE,mean squared error)

回归问题解决的是对具体数值的预测,比如房价预测、销量预测等等,解决回归问题的神经网络一般只有一个输出节点,这个节点的输出值就是预测值。本文主要介绍回归问题下的损失函数——均方误差(MSE,mean squared error)。
公式如下:
在这里插入图片描述

Pyorch实现的MSE

import torch
import numpy as np

loss_fn = torch.nn.MSELoss(reduce=False, size_average=False)

a=np.array([[1,2],[3,4]])
b=np.array([[2,3],[4,5]])

input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))

loss = loss_fn(input.float(), target.float())
print(input.float())
print(target.float())

print(loss)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述

a=np.array([[1,2],[3,4]])
b=np.array([[2,3],[4,6]])

loss_fn = torch.nn.MSELoss(reduce=True, size_average=True)

input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))

loss = loss_fn(input.float(), target.float())
print(input.float())
print(target.float())
print(loss)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/367743
推荐阅读
相关标签
  

闽ICP备14008679号