-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
37 lines (32 loc) · 971 Bytes
/
visualize.py
File metadata and controls
37 lines (32 loc) · 971 Bytes
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
import matplotlib.pyplot as plt
import csv
# read_csv reads accuracy.csv
def read_csv():
train_accuracy = []
test_accuracy = []
with open('accuracy.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
train_accuracy.append(float(row[0]))
test_accuracy.append(float(row[1]))
return train_accuracy, test_accuracy
# visualize plots accuracy over depth
def visualize(train_accuracy, test_accuracy):
depth = list(range(1, len(test_accuracy) + 1))
plt.plot(depth, train_accuracy, label='train accuracy')
plt.plot(depth, test_accuracy, label='test accuracy')
plt.title('Accuracy over Depth')
plt.xlabel('Depth')
plt.ylabel('Accuracy')
plt.legend()
plt.show()
# main reads accuracy.csv & plots accuracy over depth
def main():
try:
train_accuracy, test_accuracy = read_csv()
visualize(train_accuracy, test_accuracy)
except Exception:
print("Error: Failed to visualize data. Is data valid?")
pass
if __name__ == '__main__':
main()