我正在使用Keras训练一个ANN。训练过程使用以下命令进行:
history=model.fit(x_train,y_train,batch_size=32,epochs=500,verbose=1,validation_split = 0.2 ) #train on the noise (not moshe)fit=model.predict(x_test)loss = history.history['loss']val_loss = history.history['val_loss']
我的问题是val_loss是计算错误的总和还是平均值。
回答:
这取决于你的损失函数。通常情况下,损失是每个样本损失的平均值,例如一个非常常见的损失函数如mean_squared_error
:
def mean_squared_error(y_true, y_pred): return K.mean(K.square(y_pred - y_true), axis=-1)
显然,它是计算所有损失的平均值(均值)。
但并没有确定的答案,因为你可以传入一个自定义的损失函数来计算总和:
def sum_squared_error(y_true, y_pred): return K.sum(K.square(y_pred - y_true), axis=-1)
简而言之:通常是的,但要确保查看你使用的每个损失函数的源代码。您可以在这里找到keras
内置损失函数的源代码。