如何在Keras中提取训练集和验证集? [英] How to extract train and validation sets in Keras?

查看:483
本文介绍了如何在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)

是否可以从modelhist中提取训练和验证集?也就是说,我想知道XY中的哪些索引用于训练,哪些用于验证.

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

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屋!

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