-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplot_results.py
87 lines (64 loc) · 2.57 KB
/
plot_results.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
75
76
77
78
79
80
81
82
83
84
85
86
87
import matplotlib.pyplot as plt
import pickle
import glob
import os
import pandas as pd
from collections import defaultdict
def read_data(file_names):
with open(file_names[0], 'rb') as fp:
window_sizes = pickle.load(fp)
with open(file_names[1], 'rb') as fp:
precision = pickle.load(fp)
with open(file_names[2], 'rb') as fp:
recall = pickle.load(fp)
with open(file_names[3], 'rb') as fp:
f_measure = pickle.load(fp)
return window_sizes, precision, recall, f_measure
def plot_score_with_window_size():
file_names = ['windowsizes', 'precision', 'recall', 'fmeasure']
window_sizes, precision, recall, f_measure = read_data(file_names)
print(recall)
print(f_measure)
plt.plot(window_sizes, precision, marker='o',
color='b', linewidth=0.7, label='Precision')
plt.plot(window_sizes, recall, marker='^', linewidth=0.7, label='Recall')
plt.plot(window_sizes, f_measure, marker='D',
color='k', linewidth=0.7, label='F1 Score')
plt.xlabel('Window Size')
plt.ylabel('Score')
plt.xticks(window_sizes, window_sizes)
plt.yticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
plt.legend(loc='best')
plt.show()
def per_day_active_events(path):
file_name = '*.csv'
all_files = glob.glob(os.path.join(path, file_name))
# dict that maps day to the number of event chains active in that day
per_day_event_chains = defaultdict(int)
for f in all_files:
days_in_event_chain = {}
df = pd.read_csv(f, header=None, encoding='latin-1')
df_list = df.values.tolist()
for row in df_list:
try:
day = row[0][0:8]
days_in_event_chain[day] = True
except:
continue
for day in days_in_event_chain.keys():
per_day_event_chains[day] += 1
days = sorted(per_day_event_chains.keys())
per_day_events = []
for key in days:
per_day_events.append(per_day_event_chains[key])
return days, per_day_events
def plot_active_events(input_dir, output_dir):
days, ground_truth_events = per_day_active_events(input_dir)
days2, formed_events = per_day_active_events(output_dir)
day_numbers = range(0, len(days))
plt.plot(day_numbers, ground_truth_events, label='Ground Truth Chains')
plt.plot(day_numbers, formed_events, label='Chains formed by RevDet')
plt.xlabel('Day')
plt.ylabel('Number of Active Events')
plt.legend()
plt.show()