Train the model

history = best_model.fit(
    X_train, y_train,
    epochs=100,
    batch_size=best_params['batch_size'],
    verbose=1,
    validation_data=(X_val, y_val),
    callbacks=[checkpoint, early_stop]
) 

# Save the entire model to a file
model_save_path = r"C:\Users\....\final_model_ANN_PaDEL.h5"
best_model.save(model_save_path)

My ROC_Plot code: def plot_ROC(classifier, X, y, out_name): #------------------------------------------------------- """ Perform ROC - Curve combined with k-fold cross-validation """ from sklearn.model_selection import KFold from sklearn.metrics import roc_curve, auc

cv = KFold(n_splits=10, shuffle=True, random_state=10)
tprs = []
aucs = []
mean_fpr = np.linspace(0, 1, 100)

fig, ax = plt.subplots(figsize=(10,8))

for i, (train, test) in enumerate(cv.split(X, y)):
    X_train, y_train = X[train], y[train]
    X_test, y_test = X[test], y[test]

    classifier.fit(X_train, y_train)
    # Ensure your classifier has a method to return probabilities
    y_scores = classifier.predict(X_test)[:, 0]  # Use predict method

    fpr, tpr, thresholds = roc_curve(y_test, y_scores)
    roc_auc = auc(fpr, tpr)
    interp_tpr = np.interp(mean_fpr, fpr, tpr)
    interp_tpr[0] = 0.0
    tprs.append(interp_tpr)
    aucs.append(roc_auc)

    ax.plot(fpr, tpr, alpha=0.8, lw=1, label='ROC fold %d (AUC = %0.2f)' % (i, roc_auc))

mean_tpr = np.mean(tprs, axis=0)
mean_tpr[-1] = 1
mean_auc = auc(mean_fpr, mean_tpr)
std_auc = np.std(aucs)

ax.plot([0, 1], [0, 1], linestyle='--', lw=2, color='r', label='Chance', alpha=.8)
ax.plot(mean_fpr, mean_tpr, color='b', label=r'Mean ROC (AUC = %0.3f $\pm$ %0.3f)' % (mean_auc, std_auc), lw=2, alpha=.8)
ax.fill_between(mean_fpr, mean_tpr - np.std(tprs, axis=0), mean_tpr + np.std(tprs, axis=0), color='grey', alpha=.4, label=r'$\pm$ 1 std. dev.')

ax.set(xlim=[-0.05, 1.05], ylim=[-0.05, 1.05], title="Receiver operating characteristics: " + out_name)
ax.legend(loc="lower right", fontsize=12)
ax.set_xlabel('False Positive Rate', fontsize=12)
ax.set_ylabel('True Positive Rate', fontsize=12)
ax.tick_params(axis='both', which='major', labelsize=10)

plt.savefig("ROC curve ANN - " + out_name + ".jpg", dpi=600, transparent=True)
plt.show()
return None
0

There are 0 best solutions below