forked from Soumyabrata/EHR-features
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxplots_adding.py
67 lines (52 loc) · 2.16 KB
/
boxplots_adding.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
import numpy as np
import matplotlib.pyplot as plt
import csv
file_name = './results/performance_adding.csv'
case_array = []
accuracy_rate = []
miss_rate = []
with open(file_name, 'r') as csvFile:
reader = csv.reader(csvFile)
next(reader)
for row in reader:
case_array.append(int(row[0]))
accuracy_rate.append(float(row[8]))
miss_rate.append(float(row[9]))
csvFile.close()
case_array = np.array(case_array)
accuracy_rate = np.array(accuracy_rate)
miss_rate = np.array(miss_rate)
find_1 = np.where(case_array == 1)
find_2 = np.where(case_array == 2)
find_3 = np.where(case_array == 3)
find_4 = np.where(case_array == 4)
find_5 = np.where(case_array == 5)
find_6 = np.where(case_array == 6)
find_7 = np.where(case_array == 7)
find_8 = np.where(case_array == 8)
box1 = np.column_stack((accuracy_rate[find_1], accuracy_rate[find_2], accuracy_rate[find_3], accuracy_rate[find_4], accuracy_rate[find_5], accuracy_rate[find_6], accuracy_rate[find_7], accuracy_rate[find_8]))
box2 = np.column_stack((miss_rate[find_1], miss_rate[find_2], miss_rate[find_3], miss_rate[find_4], miss_rate[find_5], miss_rate[find_6], miss_rate[find_7], miss_rate[find_8]))
labelList =['A+HD+AG', '+HT','+M', '+W', '+SS','+G', '+BMI', '+RT']
fig, ax = plt.subplots(1, figsize=(8, 5))
bp1 = ax.boxplot(box1, positions=[1, 2, 3, 4, 5, 6, 7, 8], widths = 0.2)
print(bp1.keys())
plt.setp(bp1['boxes'], color='red')
plt.setp(bp1['fliers'], color='red')
plt.setp(bp1['caps'], color='red')
plt.setp(bp1['medians'], color='red')
plt.setp(bp1['whiskers'], color='red')
ax2 = ax.twinx()
bp2 = ax2.boxplot(box2, positions=[1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8.3], widths=0.2)
plt.setp(bp2['boxes'], color='blue')
plt.setp(bp2['fliers'], color='blue')
plt.setp(bp2['caps'], color='blue')
plt.setp(bp2['medians'], color='blue')
plt.setp(bp2['whiskers'], color='blue')
ax.set_xticklabels(labelList)
ax.set_xticks([1.15, 2.15, 3.15, 4.15, 5.15, 6.15, 7.15, 8.15])
ax.set_ylabel('Accuracy rate', fontsize=13, color='r')
ax.set_xlabel('Features combination', fontsize=14)
ax2.set_ylabel('Miss rate', fontsize=13, color='b')
ax.grid(True)
plt.savefig('./results/feature-addition.pdf', format='pdf')
plt.show()