import numpy as np import matplotlib.pyplot as plt mnist = np.load('mnist.npz') x_train = mnist['x_train']/255. y_train = np.array([np.eye(10)[n] for n in mnist['y_train']]) x_test = mnist['x_test']/255. y_test = np.array([np.eye(10)[n] for n in mnist['y_test']]) from neurons import neurons model = neurons([784,30,10]) model.fit(x_train, y_train, 20, 10, 3.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)) p_test = np.array([model.predict(x) for x in x_test]) fig = plt.figure(figsize=(10,10), dpi=80) for i in range(100): plt.subplot(10,10,i+1) plt.axis('off') plt.imshow(mnist['x_test'][i], cmap='Greys') c='Green' if y_test[i].argmax()!=p_test[i].argmax(): c='Red' plt.text(0.,0.,'$%d\\to%d$' % (y_test[i].argmax(),p_test[i].argmax()),color=c,fontsize=15) plt.show()