-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgrid_matrix_sample.py
More file actions
32 lines (26 loc) · 1.12 KB
/
Copy pathgrid_matrix_sample.py
File metadata and controls
32 lines (26 loc) · 1.12 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
from Utils.files import *
from Utils.Normalization import *
from GridMatrix.Grid import *
from GridMatrix.Validation import *
import matplotlib.pylab as plt
if __name__ == '__main__':
x_trains, y_trains, x_tests, y_tests = get_example_train_test_datasets()
x_trains = feature_scaling_datasets(x_trains)
x_tests = feature_scaling_datasets(x_tests)
# create grid with 15rows and 30columns
g = Grid(15, 30)
# find best parameters(m, n) with train error rate
#g.train(x_trains, y_trains)
# transpose time series to grid-matrix
x_matrices_train = g.dataset2Matrices(x_trains)
x_matrices_test = g.dataset2Matrices(x_tests)
# conducts 1-nn classification and gets test error rate
error_rate = one_nn_classification(x_matrices_train, y_trains, x_matrices_test, y_tests)
print('1-NN classification Test Error Rate :', error_rate)
# visualize time series representation sample
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
ax1.plot(x_tests[0])
ax2.imshow(x_matrices_test[0], interpolation='nearest', cmap='gray', aspect='auto')
plt.show()