Where to create Keras model object, inside K-fold loop, or outside? please explain why your answer is true.
def model_def():
model = Sequential()
model.add(.... so on....)
model.compile(....so on ....)
return model
Case 1:- inside the K-fold loop, so it is recreating for each loop
for train_index, test_index in kf.split(X,Y):
model = model_def()
model.fit(X[train_index],Y[test_index] ..... so on .....
or, Case 2:- outside the loop, so a single model object for all folding loop
model = model_def()
for train_index, test_index in kf.split(X,Y):
model.fit(X[train_index],Y[test_index] ..... so on .....