I have code to tune hyperparameters in LSTM. How can I:
- add cross validation based on 5 folds on training dataset
- print avg
AUC
from each iteration from training dataset divided on 5 folds - print
AUC
from test dataset (of course do not divide test dataset on folds):
def objective(trial):
start_time = time.time()
model = create_model(trial)
history = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=15, verbose=0)
y_pred = model.predict(X_test)
auc = roc_auc_score(y_test, y_pred)
end_time = time.time()
elapsed_time = end_time - start_time
print("iteration no:", trial.number)
print("AUC:", auc)
print("hyperparameters:", trial.params)
print("time:", elapsed_time, "sec")
return auc
How can I do that in Python?