Keras顺序模型中使用的验证数据是什么? [英] What is validation data used for in a Keras Sequential model?

查看:101
本文介绍了Keras顺序模型中使用的验证数据是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,传递给model.fit的验证数据用于的顺序模型吗?

My question is simple, what is the validation data passed to model.fit in a Sequential model used for?

并且,这是否会影响模型的训练方式(例如,通常使用验证集来选择模型中的超参数,但我认为这不会在这里发生)?

And, does it affect how the model is trained (normally a validation set is used, for example, to choose hyper-parameters in a model, but I think this does not happen here)?

我说的是可以像这样传递的验证集:

I am talking about the validation set that can be passed like this:

# Create model
model = Sequential()
# Add layers
model.add(...)

# Train model (use 10% of training set as validation set)
history = model.fit(X_train, Y_train, validation_split=0.1)

# Train model (use validation data as validation set)
history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test))

我研究了一下,发现keras.models.Sequential.fit调用了keras.models.training.fit,它创建了像val_accval_loss这样的变量(可以从Callbacks进行访问). keras.models.training.fit还调用keras.models.training._fit_loop,这会将验证数据添加到callbacks.validation_data,还调用keras.models.training._test_loop,这将在模型的self.test_function上成批循环验证数据.该函数的结果用于填充日志的值,这些值是可从回调中访问的值.

I investigated a bit, and I saw that keras.models.Sequential.fit calls keras.models.training.fit, which creates variables like val_accand val_loss (which can be accessed from Callbacks). keras.models.training.fit also calls keras.models.training._fit_loop, which adds the validation data to the callbacks.validation_data, and also calls keras.models.training._test_loop, which will loop the validation data in batches on the self.test_function of the model. The result of this function is used to fill the values of the logs, which are the values accessible from the callbacks.

看完所有这些内容后,我觉得传递给model.fit的验证集在训练过程中不会用于验证任何东西,它的唯一用途是获得有关训练后的模型在每个时期如何执行以实现完全独立的反馈放.因此,使用相同的验证和测试集是可以的,对吗?

After seeing all this, I feel that the validation set passed to model.fit is not used to validate anything during training, and its only use is to get feedback on how the trained model will perform in every epoch for a completely independent set. Therefore, it would be okey to use the same validation and test set, right?

除了从回调中读取数据以外,任何人都可以确认model.fit中的验证集是否还有其他目标吗?

Could anyone confirm if the validation set in model.fit has any other goal besides being read from the callbacks?

推荐答案

如果要构建实体模型,则必须遵循将数据分为三组的特定协议:一个用于培训 ,一个用于验证,另一个用于最终评估,即测试集.

If you want to build a solid model you have to follow that specific protocol of splitting your data into three sets: One for training, one for validation and one for final evaluation, which is the test set.

这个想法是,您训练自己的训练数据,并使用从验证集中获得的指标(准确性,损失等)的结果来调整模型.

The idea is that you train on your training data and tune your model with the results of metrics (accuracy, loss etc) that you get from your validation set.

您的模型没有看到"您的验证集,也没有对其进行任何培训,但是您作为超参数的设计者和主人可以根据该数据调整模型. 因此它间接影响您的模型,因为它直接影响您的设计决策.您轻推模型以使其与验证数据一起很好地工作,并且可能会引起倾斜.

Your model doesn't "see" your validation set and isn´t in any way trained on it, but you as the architect and master of the hyperparameters tune the model according to this data. Therefore it indirectly influences your model because it directly influences your design decisions. You nudge your model to work well with the validation data and that can possibly bring in a tilt.

这正是您仅根据模型和您自己未使用的数据评估模型最终得分的原因-这是第三组数据,即测试集.

Exactly that is the reason you only evaluate your models final score on data that neither your model nor you yourself has used – and that is the third chunk of data, your test set.

仅此过程可确保您对模型的质量和对从完全看不见的数据中学到的知识进行概括的能力有完整的了解.

Only this procedure makes sure you get an unaffected view of your models quality and ability to generalize what is has learned on totally unseen data.

这篇关于Keras顺序模型中使用的验证数据是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆