简体   繁体   English

用于 3 维时间序列输出的 keras 均方误差损失函数

[英]keras mean squared error loss function for 3 dimensional time series output

I would like to verify my loss function because i have read that there are issues with the mse loss function in keras.我想验证我的损失函数,因为我已经读到 keras 中的 mse 损失函数存在问题。 Consider a lstm model in keras predicting a 3d time series as multi targets (y1, y2, y3).考虑 keras 中的 lstm 模型将 3d 时间序列预测为多目标 (y1, y2, y3)。 Suppose the shape of a batch of output sequences is (10, 31, 1) Will the loss function below take the squared difference between the predicted and true output, then take the mean of the 310 samples, resulting in a single loss value?假设一批输出序列的形状是(10, 31, 1) 下面的损失函数会不会取预测输出和真实输出的平方差,然后取310个样本的均值,得到单个损失值? How would this operation happen if the 3 outputs were concatenated as (10, 31, 3)如果将 3 个输出连接为 (10, 31, 3),此操作将如何发生

def mse(y_true, y_pred):
            return keras.backend.mean(keras.backend.square(y_pred - y_true), axis=1)

If you want to get a single loss value, you need not to set axis .如果您想获得单个损失值,则无需设置axis

import keras.backend as K

def mse(y_true, y_pred):
    return K.mean(K.square(y_pred - y_true))

y_true = K.random_normal(shape=(10,31,3))
y_pred = K.random_normal(shape=(10,31,3))

loss = mse(y_true, y_pred)
print(K.eval(loss))

# print
2.0196152

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM