Commit 3e2abe83e33bc90ce6e11f0ab38fd27a80b63284

Authored by quillotm
1 parent e828890879
Exists in master

Multiple output for measure action. These multiple output are written in json.

Showing 1 changed file with 29 additions and 14 deletions Side-by-side Diff

... ... @@ -11,6 +11,7 @@
11 11 from sklearn.metrics import v_measure_score
12 12  
13 13 import core.measures
  14 +import json
14 15  
15 16  
16 17 CLUSTERING_METHODS = {
17 18  
18 19  
19 20  
20 21  
21 22  
22 23  
... ... @@ -28,26 +29,40 @@
28 29  
29 30  
30 31 def measure_run(measure: str, features: str, lst: str, truelabels: str, model: str, modeltype: str):
  32 + """
  33 +
  34 + @param measure:
  35 + @param features:
  36 + @param lst:
  37 + @param truelabels:
  38 + @param model:
  39 + @param modeltype:
  40 + @return:
  41 + """
31 42 module = CLUSTERING_METHODS[modeltype]
32 43 module.load(model)
33   - evaluation = EVALUATION_METHODS[measure]
34   - feats_dict = read_features(features)
35   - labels_dict = read_labels(truelabels)
36   - lst_dict = read_lst(lst)
37   - lst_keys = [key for key in lst_dict]
38   - feats = np.asarray([feats_dict[key] for key in lst_keys])
39   - Y_pred = module.predict(feats)
40   - Y_truth = [labels_dict[key][0] for key in lst_keys]
41 44  
42   - le = LabelEncoder()
43   - le.fit(Y_truth)
44   - Y_truth = le.transform(Y_truth)
  45 + eval = {}
  46 + for ms in measure:
  47 + evaluation = EVALUATION_METHODS[ms]
  48 + feats_dict = read_features(features)
  49 + labels_dict = read_labels(truelabels)
  50 + lst_dict = read_lst(lst)
  51 + lst_keys = [key for key in lst_dict]
  52 + feats = np.asarray([feats_dict[key] for key in lst_keys])
  53 + Y_pred = module.predict(feats)
  54 + Y_truth = [labels_dict[key][0] for key in lst_keys]
45 55  
46   - eval = evaluation(Y_truth, Y_pred)
47   - print(eval)
  56 + le = LabelEncoder()
  57 + le.fit(Y_truth)
  58 + Y_truth = le.transform(Y_truth)
48 59  
  60 + eval[ms] = evaluation(Y_truth, Y_pred)
49 61  
  62 + print(json.dumps(eval))
50 63  
  64 +
  65 +
51 66 def kmeans_run(features: str, lst: str, k:int, kmax: int, klist, output: str):
52 67 """
53 68  
... ... @@ -125,7 +140,7 @@
125 140  
126 141 parser_measure.add_argument("--measure",
127 142 required=True,
128   - type=str,
  143 + nargs="+",
129 144 choices=[key for key in EVALUATION_METHODS],
130 145 help="...")
131 146 parser_measure.add_argument("--features", required=True, type=str, help="...")