我在Keras录制'val_loss'和'val_acc'时遇到了麻烦 . 'loss'和'acc'很容易,因为它们总是记录在model.fit的历史中 .
如果在 fit
中启用了验证,则会记录'val_loss',如果启用了验证和准确性监视,则会记录 val_acc
. 但是,这是什么意思?
我的节点是model.fit(train_data,train_labels,epochs = 64,batch_size = 10,shuffle = True,validation_split = 0.2,callbacks = [history]) .
如您所见,我使用5倍交叉验证并对数据进行随机播放 . 在这种情况下,如何在'fit'中启用'validation'来记录'val_loss'和'val_acc'?
谢谢
1 回答
'val_loss' is recorded if validation is enabled in fit, and val_accis recorded if validation and accuracy monitoring are enabled.
- 如果用于上述fit方法中的callbacks参数,则来自 keras.callbacks.Callback() 对象 . 它可以用如下:如果在
fit
中启用了验证,则会记录'val_loss':使用model.fit方法时,您使用的是validatoin_split
参数,或者使用validation_data
参数to specify the tuple (x_val, y_val) or tuple (x_val, y_val, val_sample_weights) on which to evaluate the loss and any model metrics at the end of each epoch.
.在您的模型中:
如果您使用变量来保存model.fit,则使用历史回调:
history.history 将为您输出一个字典:
loss
,acc
,val_loss
和val_acc
:如下所示:您可以使用注释中给出的csvlogger或者使用更长的方法将字典写入csv文件来保存数据,如下所示writing a dictionary to a csv