赞
踩
回归问题解决的是对具体数值的预测,比如房价预测、销量预测等等,解决回归问题的神经网络一般只有一个输出节点,这个节点的输出值就是预测值。本文主要介绍回归问题下的损失函数——均方误差(MSE,mean squared error)。
公式如下:
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)
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)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。