This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
74 lines (70 loc) · 1.92 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sklearn.neural_network
from src.backbone import *
# %%
augmented = False
with_augments = "Augmented" if augmented else "Non_Augmented"
main_path = Path(os.getcwd()) / "data"
time_now = datetime.now().strftime("%d_%m_%Hh%M")
res_path = str(os.getcwd()) + "/outputs/" + time_now + "_" + with_augments
# %%
# READ DATA : Dont forget to remove subset (set to None for full data)
(
train_features,
val_features,
train_labels,
val_labels,
test_features,
test_labels,
) = load_data(main_path=main_path, subset=None)
print_shapes(
[train_features, val_features, train_labels, val_labels, test_features, test_labels]
)
# %%
# SEE IF READING WORKED + make folder for results
if not Path.is_dir(Path(res_path)):
os.mkdir(res_path)
start_time = time.time()
# %% Run entire pipeline
multi_model_run(
train_features=train_features,
test_features=test_features,
train_labels=train_labels,
test_labels=test_labels,
val_features=val_features,
val_labels=val_labels,
reduce_dims="pca",
model_list=[
KNeighborsClassifier,
RandomForestClassifier,
MLPClassifier,
DecisionTreeClassifier,
],
model_parameters=[
{"n_neighbors": [3, 4, 5, 6, 7]},
{
"max_depth": [3, 4, 5],
"n_estimators": [8, 10, 12],
"max_features": [1, 2, 3],
},
{"hidden_layer_sizes": [28, 42, 56, 70, 84], "max_iter": [1000, 1500, 2000]},
{
"random_state": [0, 1, 2, 3, 4],
"max_depth": [10, 15, 20, 25],
"max_features": [10, 15, 20, 25],
},
],
metrics=[
accuracy_score,
precision_score,
recall_score,
f1_score,
],
res_path=res_path,
folds=5,
preprocessing=augmented
)
# %%
# Save run_time to the outputs
end_time = time.time() - start_time
with open(res_path + "/outputs.csv", "a+") as f:
f.write(f"\nTime taken : {end_time}")