TransWikia.com

Cross Validation with Artificial Neural Network in Keras

Data Science Asked by Suraj on July 8, 2021

I needed to use cross-validation in the Neural network.
I used

 kf = KFold(n_splits=5, shuffle=True)

and

  for train_index, test_index in kf.split(train):
    train_X, train_y = train_XX[train_index], train_yy[train_index]

but I couldn’t manage to run. One of the errors I see is

ValueError: Cannot have number of splits n_splits=5 greater than the number of samples: n_samples=2.

I would be glad to have your suggestions if you ever tried CV with in Neural network.

One Answer

It is likely that your train variable in kf.split(train): is a list of two lists e.g. train_x and train_y or something similar. I am guessing this because the KFold API is only detecting only two entries in it, which it is unable to partition in 5 subsets (folds).

Answered by jdsuryap on July 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP