Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- X = np.asarray([[2.5, 2.5], [4, -1], [1, -4], [-3, 1.25], [-2, -4], [1, 5]]) #TOY DATASET
- Y = [1, 1, 1, 0, 0, 0]
- my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","yellow","green"]) #for the contourf plot
- sn=SigmoidNeuron() # object of class
- def plot_sn(X,Y,sn,ax,wbb): # Creates contourf plot for the current value of "w" and "b"
- X1=np.linspace(-10,10,100)
- X2=np.linspace(-10,10,100)
- XX1,XX2=np.meshgrid(X1,X2)
- YY=np.zeros(XX1.shape)
- for i in range(X2.size):
- for j in range(X1.size):
- YY[i,j]=sn.sigmoid(sn.perceptron(np.asarray([X1[j],X2[i]])))
- ax.contourf(XX1,XX2,YY,cmap=my_cmap,alpha=0.6)
- ax.scatter(X[:,0],X[:,1],c=Y,cmap=my_cmap)
- ax.plot()
- plt.figure(figsize=(10,20*6*5)) # initialize plot size
- sn.fit([2.5,2.5],1,1,1,True,False)
- ci=0
- wbb=[]
- for i in range(20):
- #ci=0
- for (x,y) in zip(X,Y):
- ci+=1
- ax=plt.subplot(20*6,1,ci)
- sn.fit(x,y,1,0.7,False,False)
- plot_sn(X,Y,sn,ax,wbb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement