From 3a64c388ef652f8eea86cd99adf6c8282be0398b Mon Sep 17 00:00:00 2001 From: joaquintb Date: Thu, 27 Jun 2024 10:33:58 +0200 Subject: [PATCH] Paths updated model_selection --- model_selection/cv_metric_gen.py | 5 ++--- model_selection/cv_metrics_distr.py | 2 +- model_selection/hyperparam_tuning.py | 2 +- model_selection/test_models.py | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/model_selection/cv_metric_gen.py b/model_selection/cv_metric_gen.py index 16c48bb..e48b8a9 100644 --- a/model_selection/cv_metric_gen.py +++ b/model_selection/cv_metric_gen.py @@ -272,15 +272,14 @@ if __name__ == "__main__": # Store the fold scores in the dataframe for metric_name, scores in fold_scores.items(): scores_df.loc[f"{model_name}_{metric_name}"] = np.around(scores, 4) - sheet_name = f"{group}_{method_names[j]}" scores_sheets[sheet_name] = scores_df # Adjust layout and save figure plt.tight_layout() - plt.savefig(f'./output_cv_metrics/curves/{group}_{method_names[j]}.svg', format='svg', dpi=500) + plt.savefig(f'./output/cv_metrics/curves/{group}_{method_names[j]}.svg', format='svg', dpi=500) plt.close(fig) # Write results to Excel file - with pd.ExcelWriter('./output_cv_metrics/metrics.xlsx') as writer: + with pd.ExcelWriter('./output./cv_metrics/metrics.xlsx') as writer: for sheet_name, data in scores_sheets.items(): data.to_excel(writer, sheet_name=sheet_name) print("Successful cv metric generation for tuned models") diff --git a/model_selection/cv_metrics_distr.py b/model_selection/cv_metrics_distr.py index 34dfc33..845eb0f 100644 --- a/model_selection/cv_metrics_distr.py +++ b/model_selection/cv_metrics_distr.py @@ -44,7 +44,7 @@ if __name__ == "__main__": if metric_name in ['F1', 'PREC', 'REC', 'ACC', 'AUROC', 'AUPRC']: ax.set_ylim(0, 1) plt.tight_layout() - fig.savefig(f'./output_cv_metrics/distributions/{group}{method}.svg', format='svg', dpi=600) + fig.savefig(f'./output/cv_metrics/distributions/{group}{method}.svg', format='svg', dpi=600) plt.close(fig) # Close the figure to free up memory print("Succesful distribution plots generation") diff --git a/model_selection/hyperparam_tuning.py b/model_selection/hyperparam_tuning.py index d98dfb0..2d6bf19 100644 --- a/model_selection/hyperparam_tuning.py +++ b/model_selection/hyperparam_tuning.py @@ -159,7 +159,7 @@ if __name__ == "__main__": sheets_dict[sheet_name] = hyperparam_df # Write results to Excel file - with pd.ExcelWriter('./output_hyperparam/hyperparamers.xlsx') as writer: + with pd.ExcelWriter('./output/hyperparam/hyperparamers.xlsx') as writer: for sheet_name, data in sheets_dict.items(): data.to_excel(writer, sheet_name=sheet_name) diff --git a/model_selection/test_models.py b/model_selection/test_models.py index 8ab1b46..3652f29 100644 --- a/model_selection/test_models.py +++ b/model_selection/test_models.py @@ -77,7 +77,7 @@ def read_data(): def get_tuned_models(group_str, method_str): # Read sheet corresponding to group and method with tuned models and their hyperparam - tuned_models_df = pd.read_excel("./output_hyperparam/hyperparamers.xlsx",sheet_name=f"{group_str}_{method_str}") + tuned_models_df = pd.read_excel("./output/hyperparam/hyperparamers.xlsx",sheet_name=f"{group_str}_{method_str}") # Mapping from model abbreviations to sklearn model classes model_mapping = { 'DT': DecisionTreeClassifier, @@ -274,13 +274,13 @@ if __name__ == "__main__": # ---------------------------------------------------------- # Adjust layout and save/show figure plt.tight_layout() - plt.savefig(f'./output_test/plots/{group}_{method_names[j]}.svg', format='svg', dpi=500) + plt.savefig(f'./output/testing/plots/{group}_{method_names[j]}.svg', format='svg', dpi=500) plt.close(fig) # Store the DataFrame in the dictionary with a unique key for each sheet sheet_name = f"{group}_{method_names[j]}" scores_sheets[sheet_name] = scores_df # Write results to Excel file - with pd.ExcelWriter('./output_test/testing_tuned_models.xlsx') as writer: + with pd.ExcelWriter('./output/testing/testing_tuned_models.xlsx') as writer: for sheet_name, data in scores_sheets.items(): data.to_excel(writer, sheet_name=sheet_name) print("Successful evaluation with test dataset") -- 2.24.1