-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
183 lines (138 loc) · 4.3 KB
/
test.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
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
from main import *
import matplotlib.pyplot as plt
def test_load_data():
"""
Test load_data by printing the data read
"""
classifier = Classifier()
classifier.load_data()
print(classifier.x)
print(classifier.y)
print(classifier.x_header)
# test_load_data()
def test_load_data_panda():
"""
Test load_data_panda by printing the data read
"""
classifier = Classifier()
classifier.load_data_panda()
print(classifier.x)
print(classifier.y)
# test_load_data_panda()
def test_basic_classifier():
"""
Test the basic classifier given
"""
classifier = Classifier()
classifier.load_data_panda()
classifier.basic_classifier()
# test_basic_classifier()
def test_decision_tree():
"""
Testing Decision Tree for different depths (best result with D=5)
:return: show plot
"""
classifier = Classifier()
classifier.load_data_panda()
classifier.preprocessing()
Ds = range(2, 15)
accuracys = []
for D in Ds:
print(D)
accuracys.append(classifier.decision_tree(D))
plt.plot(Ds, accuracys, label="accuracy % D")
plt.show()
# test_decision_tree()
def test_ada_boot():
"""
Adaboost Test for Different values of D (best with D=2)
:return: show plot
"""
classifier = Classifier()
classifier.load_data_panda()
classifier.preprocessing()
Ds = range(2, 15)
accuracys = []
for D in Ds:
print(D)
accuracys.append(classifier.ada_boost(D))
plt.plot(Ds, accuracys, label="accuracy % D")
plt.show()
# test_ada_boot()
def test_NN_1():
"""
NN Test with sgd, different constant lr, 1 hidden layer of varying size
:return: show plot
"""
classifier = Classifier()
classifier.load_data_panda()
classifier.preprocessing()
lrs = [(2 ** n) * 0.0001 for n in range(11)]
sizes = [(20 + 10 * n,) for n in range(20)]
accuracies = np.zeros((len(lrs), len(sizes)))
for i in range(len(lrs)):
for j in range(len(sizes)):
accuracies[i, j] = classifier.NN(hl_sizes=sizes[j], lr=lrs[i])
idx = np.argsort(accuracies, axis=0)
plt.figure(1)
plt.plot(sizes, [lrs[i] for i in idx[-1, :]], label="best learning rate for each hidden layer size")
plt.figure(2)
plt.plot(sizes, [accuracies[idx[-1, i], i] for i in range(len(sizes))], label="corresponding accuracies")
plt.show()
# test_NN_1()
def test_NN_2():
"""
NN test for higher hidden layer sizes (from 200 to 400)
:return: show plot
"""
classifier = Classifier()
classifier.load_data_panda()
classifier.preprocessing()
lrs = [(2 ** n) * 0.0001 for n in range(11)]
sizes = [(200 + 10 * n,) for n in range(20)]
accuracies = np.zeros((len(lrs), len(sizes)))
for i in range(len(lrs)):
for j in range(len(sizes)):
accuracies[i, j] = classifier.NN(hl_sizes=sizes[j], lr=lrs[i])
idx = np.argsort(accuracies, axis=0)
plt.figure(1)
plt.plot(sizes, [lrs[i] for i in idx[-1, :]], label="best learning rate for each hidden layer size")
plt.figure(2)
plt.plot(sizes, [accuracies[idx[-1, i], i] for i in range(len(sizes))], label="corresponding accuracies")
plt.show()
# test_NN_2()
def test_LDA():
classifier = Classifier()
classifier.load_data_panda()
classifier.preprocessing()
classifier.LDA()
# test_LDA()
def test_SVM():
classifier = Classifier()
classifier.load_data_panda()
classifier.load_test()
classifier.preprocessing(change_ages=True)
classifier.apply_pca()
classifier.SVM()
classifier.test()
classifier.generate_submission(submission_file="Data/submission_svm.csv")
test_SVM()
def test_KNN():
classifier = Classifier()
classifier.load_data_panda()
classifier.load_test()
classifier.preprocessing(change_ages=True)
classifier.apply_pca()
classifier.KNN()
classifier.test()
classifier.generate_submission(submission_file="Data/submission_knn.csv")
# test_KNN()
def test_random_forest():
classifier = Classifier()
classifier.load_data_panda()
classifier.load_test()
classifier.preprocessing(change_ages=True)
classifier.random_forest()
classifier.test()
classifier.generate_submission(submission_file="Data/submission_random_forest.csv")
# test_random_forest()