Skip to content

Commit 015e736

Browse files
committed
I have added the auto create of the output folders.
1 parent bba1245 commit 015e736

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/training_and_evaluate_functions/run_program.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def train_and_compare_models(rf_name, bert_name, hf_name):
3939
)
4040
)
4141

42+
# Create saving folder if not existing yet
43+
rf_path = os.path.join(saving_path, "random_forest")
44+
if not os.path.exists(rf_path):
45+
os.makedirs(rf_path)
46+
bert_path = os.path.join(saving_path, "bert")
47+
if not os.path.exists(bert_path):
48+
os.makedirs(bert_path)
49+
4250
# Parameter for the training of a model with random forest algorithm
4351
random_forest_parameter_normal = {
4452
"n_estimators": 450,
@@ -59,13 +67,11 @@ def train_and_compare_models(rf_name, bert_name, hf_name):
5967

6068
# Model trained with random forest algorithm
6169
rf_save_path = os.path.join(
62-
saving_path,
63-
"random_forest",
70+
rf_path,
6471
rf_name+".joblib"
6572
)
6673
rf_log_path = os.path.join(
67-
saving_path,
68-
"random_forest",
74+
rf_path,
6975
rf_name+".log"
7076
)
7177

@@ -89,10 +95,10 @@ def train_and_compare_models(rf_name, bert_name, hf_name):
8995
max_features=3000,
9096
training_parameters=random_forest_parameter_normal
9197
)
92-
print(f"Rnadom forest {rf_name} successfully trained.")
98+
print(f"Random forest {rf_name} successfully trained.")
9399
# Model trained with BERT algorithm
94-
bert_save_path = os.path.join(saving_path, "bert", bert_name)
95-
bert_log_path = os.path.join(saving_path, "bert", bert_name+".log")
100+
bert_save_path = os.path.join(bert_path, bert_name)
101+
bert_log_path = os.path.join(bert_path, "bert", bert_name+".log")
96102

97103
# Check if the paths are free
98104
if os.path.isfile(bert_save_path) is True:

0 commit comments

Comments
 (0)