Ich habe Programm von neuronalen Netzwerk in Python mit Hilfe von neuralnetworksanddeeplearning.com gemacht. In dem ich hiddenLayer Gewichtung von (784,100) und outputLayer Gewichtung (100,10) zufällig initialisiert hat. Algorithmus arbeitet an Minibatch-basierten Theorie und Regularisierung overfitting mit mnist.pkl.gz Datensatz. Ich verwende Minibatch der Größe 10, Lernrate (Eta) = 3, Regularisierungsparameter = 2,5. Nach dem Programmlauf erhöht sich die Genauigkeit und sinkt dann ...... Also bitte hilf mir, wie ich es besser machen kann, um mehr Genauigkeit zu bekommen. folgende sind die iterationen des algorithmus. Vielen Dank im Voraus ..Genauigkeit des neuronalen Netzes sinkt
>>> stochastic(training_data,10,20,hiddenW,outW,hiddenB,outB,3,test_data,2.5)
Epoch 0 correct data: 9100.0/10000
Total cost of test data [ 307.75991542]
Epoch 1 correct data: 9136.0/10000
Total cost of test data [ 260.61199829]
Epoch 2 correct data: 9233.0/10000
Total cost of test data [ 244.9429907]
Epoch 3 correct data: 9149.0/10000
Total cost of test data [ 237.08391208]
Epoch 4 correct data: 9012.0/10000
Total cost of test data [ 227.14709858]
Epoch 5 correct data: 8714.0/10000
Total cost of test data [ 215.23668711]
Epoch 6 correct data: 8694.0/10000
Total cost of test data [ 201.79958056]
Epoch 7 correct data: 8224.0/10000
Total cost of test data [ 193.37639124]
Epoch 8 correct data: 7915.0/10000
Total cost of test data [ 183.83249811]
Epoch 9 correct data: 7615.0/10000
Total cost of test data [ 166.59631548]
# forward proppagation with with bais 3 para
def forward(weight,inp,b):
val=np.dot(weight.T,inp)+b
return val
# sigmoid function
def sigmoid(x):
val=1.0/(1.0+np.exp(-x))
return val
# Backpropagation for gradient check
def backpropagation(x,weight1,weight2,bais1,bais2,yTarget):
hh=forward(weight1,x,bais1)
hhout=sigmoid(hh)
oo=forward(weight2,hhout,bais2)
oout=sigmoid(oo)
ooe=-(yTarget-oout)*(oout*(1-oout))
hhe=np.dot(weight2,ooe)*(hhout*(1-hhout))
a2=np.dot(hhout,ooe.T)
a1=np.dot(x,hhe.T)
b1=hhe
b2=ooe
return a1,a2,b1,b2
def totalCost(data,weight1,weight2,bais1,bais2,lmbda):
m=len(data)
cost=0.0
for x,y in data:
hh=forward(weight1,x,bais1)
hhout=sigmoid(hh)
oo=forward(weight2,hhout,bais2)
oout=sigmoid(oo)
c=sum(-y*np.log(oout)-(1-y)*np.log(1-oout))
cost=cost+c/m
cost=cost+0.5*(lmbda/m)*(sum(map(sum,(weight1**2)))+sum(map(sum,(weight2**2))))
return cost
def stochastic(tdata,batch_size,epoch,w1,w2,b1,b2,eta,testdata,lmbda):
n=len(tdata)
for j in xrange(epoch):
random.shuffle(tdata)
mini_batches = [tdata[k:k+batch_size]for k in xrange(0, n, batch_size)]
for minibatch in mini_batches:
w1,w2,b1,b2=updateminibatch(minibatch,w1,w2,b1,b2,eta,lmbda)
print 'Epoch {0} correct data: {1}/{2}'.format(j,evaluate(testdata,w1,w2,b1,b2),len(testdata))
print 'Total cost of test data {0}'.format(totalCost(testdata,w1,w2,b1,b2,lmbda))
return w1,w2,b1,b2
def updateminibatch(data,w1,w2,b1,b2,eta,lmbda):
n=len(training_data)
q1=np.zeros(w1.shape)
q2=np.zeros(w2.shape)
q3=np.zeros(b1.shape)
q4=np.zeros(b2.shape)
for xin,yout in data:
delW1,delW2,delB1,delB2=backpropagation(xin,w1,w2,b1,b2,yout)
q1=q1+delW1
q2=q2+delW2
q3=q3+delB1
q4=q4+delB2
w1=(1-eta*(lmbda/n))*w1-(eta/len(data))*q1
w2=(1-eta*(lmbda/n))*w2-(eta/len(data))*q2
b1=b1-(eta/len(data))*q3
b2=b2-(eta/len(data))*q4
return w1,w2,b1,b2
def evaluate(testdata,w1,w2,b1,b2):
i=0
z=np.zeros(len(testdata))
for x,y in testdata:
h=forward(w1,x,b1)
hout=sigmoid(h)
o=forward(w2,hout,b2)
out=sigmoid(o)
p=np.argmax(out)
if (p==y):
a=int(p==y)
z[i]=a
i=i+1
return sum(z)
danke ... deine Antwort hilf mir .... :) Validierungstest machen gute Genauigkeitsrate. –
Validierung lässt Sie Muster beseitigen, die nicht gelernt sind (es ist nicht gut, System, um alle Muster zu lernen und nicht mit wenigen Mustern genau zu sein). Versuche, Muster zu mischen. Warum verwenden Sie kein bipolares Netzwerk [0-1] oder [-1 bis 1]? – SACn