-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_saver.py
More file actions
200 lines (179 loc) · 9.52 KB
/
plot_saver.py
File metadata and controls
200 lines (179 loc) · 9.52 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import matplotlib.pyplot as plt
import pandas as pd
import os
def plot_n_save(files, labels, filename, show = False):
"""
Function to save plots based on the directories given in files and labels given in labels.
The plots are saved in the Plots directory with the name filename.
Parameters
----------
files : list
List of directories where the plots are to be saved
labels : list
List of information for the plots
filename : str
Name of the file to be saved
show : bool, Default False
Whether to show the plot or not
"""
plt.figure(figsize=(10, 10))
for i in range(len(files)):
directory = files[i]
legend_label = labels[i]
df = pd.read_csv(directory)
# Get the first column of df
x = df.iloc[:, 0]
# Get the second column of df
y = df.iloc[:, 1]
plt.plot(x, y, label = legend_label)
plt.xlabel('Models')
plt.ylabel('Average Perplexity')
plt.title('Models vs Average Perplexity')
plt.legend()
# Check if a directory named "Plots" exists and create it if it doesn't
if not os.path.exists('Plots'):
os.makedirs('Plots')
plt.savefig('Plots\\' + filename + '.png')
if show:
plt.show()
plt.close()
def caller():
"""
Function to call the plot_n_save function
"""
# Create a list of the directories where to fetch the data fram and the labels for the plots
# Plot and save Turing Smoothing
files = ['average_perplexity\\avg_perplexity_turing_smoothing_test.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_train.csv']
labels = ['Turing Smoothing Test',
'Turning Smoothing Train']
filename = 'Turing'
plot_n_save(files, labels, filename, show = False)
# Plot and save Laplace Smoothing
files = ['average_perplexity\\avg_perplexity_laplace_smoothing_test.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_train.csv']
labels = ['Laplace Smoothing Test',
'Laplace Smoothing Train']
filename = 'Laplace'
plot_n_save(files, labels, filename, show = False)
# Plot and save None Smoothing
files = ['average_perplexity\\avg_perplexity_None_smoothing_train.csv']
labels = ['No Smoothing Train']
filename = 'No_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save Additive Smoothing for all values of K
files = ['average_perplexity\\avg_perplexity_additive_0.01_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.01_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_train.csv']
labels = ['Additive Smoothing with K = 0.01 Test',
'Additive Smoothing with K = 0.1 Test',
'Additive Smoothing with K = 10 Test',
'Additive Smoothing with K = 100 Test',
'Additive Smoothing with K = 0.01 Train',
'Additive Smoothing with K = 0.1 Train',
'Additive Smoothing with K = 10 Train',
'Additive Smoothing with K = 100 Train']
filename = 'Additive_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save Additive Smoothing and Laplace Smoothing for all values of K
files = ['average_perplexity\\avg_perplexity_additive_0.01_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.01_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_train.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_test.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_train.csv']
labels = ['Additive Smoothing with K = 0.01 Test',
'Additive Smoothing with K = 0.1 Test',
'Additive Smoothing with K = 10 Test',
'Additive Smoothing with K = 100 Test',
'Additive Smoothing with K = 0.01 Train',
'Additive Smoothing with K = 0.1 Train',
'Additive Smoothing with K = 10 Train',
'Additive Smoothing with K = 100 Train',
'Laplace Smoothing Test',
'Laplace Smoothing Train']
filename = 'Additive_Laplace_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save None Smoothing and Turing Smoothing
files = ['average_perplexity\\avg_perplexity_None_smoothing_train.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_test.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_train.csv']
labels = ['No Smoothing Train',
'Turing Smoothing Test',
'Turing Smoothing Train']
filename = 'Turing_No_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save None Smoothing and Laplace Smoothing
files = ['average_perplexity\\avg_perplexity_None_smoothing_train.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_test.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_train.csv']
labels = ['No Smoothing Train',
'Laplace Smoothing Test',
'Laplace Smoothing Train']
filename = 'Laplace_No_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save None Smoothing and Additive Smoothing for all values of K
files = ['average_perplexity\\avg_perplexity_additive_0.01_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.01_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_train.csv',
'average_perplexity\\avg_perplexity_None_smoothing_train.csv']
labels = ['Additive Smoothing with K = 0.01 Test',
'Additive Smoothing with K = 0.1 Test',
'Additive Smoothing with K = 10 Test',
'Additive Smoothing with K = 100 Test',
'Additive Smoothing with K = 0.01 Train',
'Additive Smoothing with K = 0.1 Train',
'Additive Smoothing with K = 10 Train',
'Additive Smoothing with K = 100 Train',
'No Smoothing Train']
filename = 'Additive_No_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save Laplace Smoothing and Turing Smoothing
files = ['average_perplexity\\avg_perplexity_laplace_smoothing_test.csv',
'average_perplexity\\avg_perplexity_laplace_smoothing_train.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_test.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_train.csv']
labels = ['Laplace Smoothing Test',
'Laplace Smoothing Train',
'Turing Smoothing Test',
'Turing Smoothing Train']
filename = 'Laplace_Turing_Smoothing'
plot_n_save(files, labels, filename, show = False)
# Plot and save Turing and Additive Smoothing for all values of K
files = ['average_perplexity\\avg_perplexity_additive_0.01_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_test.csv',
'average_perplexity\\avg_perplexity_additive_0.01_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_0.1_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_10_smoothing_train.csv',
'average_perplexity\\avg_perplexity_additive_100_smoothing_train.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_test.csv',
'average_perplexity\\avg_perplexity_turing_smoothing_train.csv']
labels = ['Additive Smoothing with K = 0.01 Test',
'Additive Smoothing with K = 0.1 Test',
'Additive Smoothing with K = 10 Test',
'Additive Smoothing with K = 100 Test',
'Additive Smoothing with K = 0.01 Train',
'Additive Smoothing with K = 0.1 Train',
'Additive Smoothing with K = 10 Train',
'Additive Smoothing with K = 100 Train',
'Turing Smoothing Test',
'Turing Smoothing Train']
filename = 'Additive_Turing_Smoothing'
plot_n_save(files, labels, filename, show = False)
caller()