Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract train and validation sets in 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)

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.

like image 530
yohai Avatar asked Oct 31 '25 01:10

yohai


1 Answers

Keras splits the dataset at

split_at = int(x[0].shape * (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.

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))
like image 150
YSelf Avatar answered Nov 02 '25 07:11

YSelf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!