import numpy as np import matplotlib.pyplot as plt mnist = np.load('mnist.npz') x_train = mnist['x_train'][mnist['y_train']<=1]/255. y_train = mnist['y_train'][mnist['y_train']<=1] x_test = mnist['x_test'][mnist['y_test']<=1]/255. y_test = mnist['y_test'][mnist['y_test']<=1] x_train = np.array([[img.mean(),img[10:18,11:17].mean()] for img in x_train]) y_train = np.array([[[1,0],[0,1]][n] for n in y_train]) x_test = np.array([[img.mean(),img[10:18,11:17].mean()] for img in x_test]) y_test = np.array([[[1,0],[0,1]][n] for n in y_test]) from neurons import neurons model = neurons([2,5,5,2]) model.fit(x_train, y_train, 20, 30, 1.0) print('Performance (training)') print('Loss: %.5f, Acc: %.5f' % model.evaluate(x_train, y_train)) print('Performance (testing)') print('Loss: %.5f, Acc: %.5f' % model.evaluate(x_test, y_test)) out = np.array([model.predict(x) for x in x_train]) fig = plt.figure(figsize=(6,6), dpi=80) plt.subplot(2,1,1) plt.hist(out[:,0][y_train[:,0]==1], bins=50, color='y') plt.hist(out[:,0][y_train[:,1]==1], bins=50, color='g', alpha=0.5) plt.subplot(2,1,2) plt.hist(out[:,1][y_train[:,0]==1], bins=50, color='y') plt.hist(out[:,1][y_train[:,1]==1], bins=50, color='g', alpha=0.5) plt.show()