hi.
I couldn't understand the k-fold method in deep learning.
I know what is happening.
I mean look at this code :
k = 3
num_validation_samples = len(data) // k
np.random.shuffle(data)
val_scores = []
for fold in range(k):
print(f'Doing fold {fold}')
val_data = data[num_validation_samples * fold:
num_validation_samples * (fold + 1)]
training_data = np.concatenate(
[data[:num_validation_samples * fold],
data[num_validation_samples * (fold + 1):]]
)
model = get_model()
x_train = np.concatenate([np.expand_dims(training_data[:,0],1), np.expand_dims(training_data[:,1],1)], axis=1)
y_train = np.expand_dims(training_data[:,2], 1)
model.fit(x_train, y_train,
batch_size=2**5,
epochs=20,
verbose=0)
x_test = np.concatenate([np.expand_dims(val_data[:,0],1), np.expand_dims(val_data[:,1],1)], axis=1)
y_test = np.expand_dims(val_data[:,2], 1)
val_score, val_acc = model.evaluate(x_test, y_test, verbose=0)
val_scores.append(val_acc)
val_score = np.mean(val_scores)
print(val_score)
model = get_model()
history = model.fit(X, y,
epochs=20,
batch_size=2**5,
verbose=0)
test_score = model.evaluate(X_test,y_test)
in each iteration, we recreate the model. We just see the val_score at the end. and after that, we again recreate the model with random parameters and retrain and reevaluate it. why?