-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (70 loc) · 2.48 KB
/
Copy pathmain.py
File metadata and controls
97 lines (70 loc) · 2.48 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# ----------------------------------
# Creating virtualenv:
# ----------------------------------
# >> virtualenv last
# >> source last/bin/activate
# >> pip install -r requirements.txt
# ----------------------------------
# ----------------------------------
# How to run:
# main.py [dataset] [featureExtract] [algorithm] [seed]
# ----------------------------------
# ----------------------------------
import sys
import os
import src.config as config
import pickle as pickle
from src.runExperiment import runExperiment
# ----------------------------------
# ----------------------------------
if __name__ == "__main__":
# load sys.arg scripts
if(len(sys.argv) != 5):
print("Usage: main.py [dataset] [featureExtract] [algorithm] [seed]")
sys.exit(1)
# check if dataset is valid
if(not(sys.argv[1] in config.VALID_DATASETS)):
print("Dataset is not valid")
sys.exit(1)
# check if featureExtract is valid
if(not(sys.argv[2] in config.VALID_FEATURES)):
print("Feature Type is not valid")
sys.exit(1)
# check if algorithm is valid
if(not(sys.argv[3])in config.VALID_ALGORITHMS):
print("Algorithm is not valid")
sys.exit(1)
# check if seed is valid
if(not(sys.argv[4].isdigit()) and int(sys.argv[4]) < 0):
print("Seed is not valid")
sys.exit(1)
# ----------------
# For debugging
# ----------------
# dataset = "user_reviews_g1"
# algorithm = "KNN"
# featureExtract = "TFIDF"
# seed = 0
# ----------------
# ----------------
dataset = sys.argv[1]
featureExtract = sys.argv[2]
algorithm = sys.argv[3]
seed = int(sys.argv[4])
output_file = "output/results_" + dataset + "_" + featureExtract + "_" + algorithm + "_seed_" + str(seed) + ".pkl"
print(output_file)
# check if output file exists
if(os.path.exists(output_file)):
print("\n - Output file already exists. Not running again!")
sys.exit(1)
# othersise, we can run experiments
results = runExperiment(dataset = dataset, featureExtract = featureExtract,
algorithm = algorithm, seed = seed)
# create output dir if not exists
os.makedirs("output", exist_ok=True)
# save results
print(" - Saving Results")
pickle.dump(results, file = open(output_file, "wb"))
print(" - Finished :)")
# ----------------------------------
# ----------------------------------