1

It easy to do k-Fold Cross Validation by using scikit-learn package. There we separately use data and labels. However, here combine data and labels before feeding into model. like:

 tf.data.Dataset.from_tensor_slices((X, Y))
        .shuffle(batch_size * 100)
        .batch(batch_size)

In this case how to do K-fold cross validation?

Ahmad
  • 645
  • 2
  • 6
  • 21
  • What is `X` and `Y`? – AloneTogether Apr 07 '22 at 13:13
  • X is input data suppose 333456,6 and y is labels 333456 – Ahmad Apr 07 '22 at 13:33
  • Here is an example: https://github.com/fenwickslab/fenwicks/blob/2d539634efe829bd5a2e2c1b9c837819a89bb707/data.py#L370 – AloneTogether Apr 07 '22 at 13:44
  • @AloneTogether it is not clear and complex one. Can you describe by using some toy example? – Ahmad Apr 07 '22 at 14:24
  • First try, then we can take a look. – AloneTogether Apr 08 '22 at 08:01
  • I simply ignore to use sickit-lern package for cross validation. I manually implemented by me self. Here is the code: `cvscores = [] for i in range(3): X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size = 0.1) model = modeling(X_train, y_train, X_test, y_test) f_score = test_model(X_test, y_test) cvscores.append(f_score) sum=0; for j in range(3): print(f"CrossFold: {i}", cvscores[i]) sum=sum+cvscores[i] average = sum/3 print(f"average: {average}")`. Please verify this code? – Ahmad Apr 08 '22 at 14:25
  • Have you check this: https://stackoverflow.com/questions/71676222/how-apply-kfold-cross-validation-using-tf-keras-utils-image-dataset-from-directo/71678692#71678692 – AloneTogether Apr 08 '22 at 16:08

0 Answers0