如何在Keras中提取训练集和验证集? [英] How to extract train and validation sets in Keras?
问题描述
我在keras
中实现了一个神经网络,其结构如下:
I implement a neural net in keras
, with the following structure:
model = Sequential([... layers ...])
model.compile(optimizer=..., loss=...)
hist=model.fit(x=X,y=Y, validation_split=0.1, epochs=100)
是否可以从model
或hist
中提取训练和验证集?也就是说,我想知道X
和Y
中的哪些索引用于训练,哪些用于验证.
Is there a way to extract from either model
or hist
the train and validation sets? That is, I want to know which indices in X
and Y
were used for training and which were used for validation.
推荐答案
Keras splits the dataset at
split_at = int(x[0].shape * (1-validation_split))
进入训练和验证部分.因此,如果您有n
个样本,则第一个int(n*(1-validation_split))
个样本将是训练样本,其余的是验证集.
into the train and validation part. So if you have n
samples, the first int(n*(1-validation_split))
samples will be the training sample, the remainder is the validation set.
如果您想拥有更多控制权,则可以自己拆分数据集,并使用参数validation_data
传递验证数据集:
If you want to have more control, you can split the dataset yourself and pass the validation dataset with the parameter validation_data
:
model.fit(train_x, train_y, …, validation_data=(validation_x, validation_y))
这篇关于如何在Keras中提取训练集和验证集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!