-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot.py
More file actions
61 lines (54 loc) · 1.62 KB
/
plot.py
File metadata and controls
61 lines (54 loc) · 1.62 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
import argparse
import matplotlib.pyplot as plt
import numpy as np
import csv
parser = argparse.ArgumentParser()
parser.add_argument('--file', type=str, default='statistics.csv', help='file with data')
opt = parser.parse_args()
print(opt)
classes = []
utility = []
privacy = []
pPerAttribute = []
uPerAttribute = []
utotal = 0
ptotal = 0
with open(opt.file, 'r') as f:
reader = csv.reader(f)
for row in reader:
classes.append(row[0])
utility.append(float(row[1]))
privacy.append((100-float(row[1])))
for num in utility:
utotal += num
uPerAttribute.append(utotal/(len(uPerAttribute)+1))
utotal = utotal/(len(utility))
for num in privacy:
ptotal += num
pPerAttribute.append(ptotal/(len(pPerAttribute)+1))
ptotal = ptotal/(len(privacy))
plt.figure(figsize=(15,8))
plt.subplot(2,1,2)
plt.ylabel('Utility (%)')
plt.xlabel('Attribute')
plt.title("Dataset Utility per Attribute")
plt.plot(classes,utility)
plt.scatter(classes,utility)
plt.subplot(2,2,1)
plt.ylabel('Utility (%)')
plt.xlabel('Number of Attributes')
plt.title("Dataset Utility per # of Attributes")
plt.axis([0,len(utility),0,100])
z = np.polyfit(range(0,len(uPerAttribute)), uPerAttribute,4)
p = np.poly1d(z)
plt.plot(range(0,len(uPerAttribute)),p(range(0,len(uPerAttribute))),'r:')
plt.subplot(2,2,2)
plt.ylabel('Privacy (%)')
plt.xlabel('Number of Attributes')
plt.title("Dataset Privacy per # of Attributes")
plt.axis([0,len(privacy),0,100])
z = np.polyfit(range(0,len(pPerAttribute)), pPerAttribute,4)
p = np.poly1d(z)
plt.plot(range(0,len(pPerAttribute)),p(range(0,len(pPerAttribute))),'r:')
plt.plot(range(0,len(classes)),p(range(0,len(classes))),'b:')
plt.show()