-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_MNIST.py
42 lines (33 loc) · 881 Bytes
/
classify_MNIST.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
from random import sample
import numpy as np
import matplotlib.pyplot as plt
from mnist import MNIST
from nngp import NNGP
n_train = 1000
n_test = 200
sigma_eps = 0.01
sigma_w_2 = 1.45
sigma_b_2 = 0.28
L = 3
data = MNIST('../../Data/MNIST/raw')
data_vectors, labels = data.load_training()
data_vectors, labels = np.array(data_vectors), np.array(labels)
print('Loaded MNIST')
training_data = data_vectors[:n_train]
test_data = data_vectors[n_train:n_train + n_test]
training_labels = labels[:n_train]
test_labels = labels[n_train:n_train+n_test]
classifier = NNGP(
training_data,
training_labels,
test_data,
L,
sigma_eps_2=sigma_eps**2,
sigma_w_2=sigma_w_2,
sigma_b_2=sigma_b_2,
classify=True
)
classifier.train()
predicted_labels = classifier.classify()
accuracy = np.mean(predicted_labels == test_labels)
print(f'accuray = {accuracy}')