In [1]:
import ANN
%matplotlib inline
import matplotlib
matplotlib.rcParams['figure.figsize'] = (18,7)
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from IPython import display

In [2]:
data = load_iris()
Input = data.data
target = data.target

In [3]:
numLayers = 3
iterations = 2000
eta = 0.005

nn1 = ANN.FNN(numLayers, Input, target, eta=eta)
#output, error = nn1.train(iterations)


Class labels:set([0, 1, 2])
Network constructed with 3 layers, learning rate is 0.005
Layers connected

In [4]:
target = nn1.__target__

error = []
output = []

In [5]:
plt.ion()

f, ax = plt.subplots(1,2)

im = ax[0].imshow(target, interpolation = 'none', cmap='viridis', origin='lower', aspect='auto', vmin= 0., vmax = 1.)
ax[0].set_yticks([0,1,2])
ax[0].set_yticklabels(['0', '1', '2'])
ax[0].set_ylabel("Classes")
ax[0].set_xlabel("Data Points")
ax[0].set_title('Target classes')

f.colorbar(im, ax=ax[0])
cost = ax[1].plot(error, c='k')
ax[1].set_title("Change in cost Function")
ax[1].set_xlabel("Iterations")
ax[1].set_ylabel("Cost Function")
f.canvas.draw()



In [6]:
for i in range(iterations):
    out, e = nn1.train()
    output.append(out)
    error.append(e)
    if i % 5 == 0: # Every 5th iteration
        try:
            im.set_data(out) 
            ax[1].plot(error, c='k')
            f.canvas.draw()
            display.display(f)
            ax[1].cla()
            display.clear_output(wait=True)
            #plt.pause(0.001)
    
        except KeyboardInterrupt:
            break
plt.ioff()
plt.close()