嘿伙计们,我需要一些关于我的 pybrain 代码的帮助。一切都很好,但是在第一次训练之后,训练错误并没有下降。事实上,它只是停留在 13.3484055174 处。我已经多次检查我的代码并将其与其他示例进行比较,但我一直遇到同样的问题。我也已经尝试过更改隐藏单元的数量、学习率、动量、权重衰减,但无济于事。我检查了参数,它从 [-1 到 1] 开始,然后上升到 ~240-250。我想知道是否有人可以看到它为什么不起作用。我敢肯定这是我缺少的一个非常简单的 1-liner。
我正在研究 kaggle 0-9 数字分类数据集。我已经让随机森林工作了,但我真的想让这个神经网络也能工作。任何帮助将不胜感激。
#learn digit classification with a nerual network
import pybrain
from pybrain.datasets import *
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.modules import SoftmaxLayer
from pybrain.utilities import percentError
import numpy
print "Importing training and test data"
data = numpy.genfromtxt('trainR.csv', delimiter = ',')
data = data[1:]
traindata = data[:(len(data)/2)]
testdata = data[(len(data)/2)+1:]
print "Importing actual data"
actualdata = numpy.genfromtxt('trainR.csv', delimiter = ',')
print "Adding samples to dataset and setting up neural network"
ds = ClassificationDataSet(784, 10, nb_classes = 10)
for x in traindata:
ds.addSample(tuple(x[1:]),tuple(x[0:1]))
ds._convertToOneOfMany( bounds=[0,1] )
net = buildNetwork(784, 100, 10, bias=True, outclass=SoftmaxLayer)
print "Training the neural network"
trainer = BackpropTrainer(net, dataset=ds, momentum = 0.1,
verbose = True, weightdecay = 0.01)
for i in range(3):
# train the network for 1 epoch
trainer.trainEpochs( 1 )
# evaluate the result on the training and test data
trnresult = percentError( trainer.testOnClassData(), [x[0] for x in traindata] )
# print the result
print "epoch: " + str(trainer.totalepochs) + " train error: " + str(trnresult)
print ""
print "Predicting with the neural network"
answerlist = []
for row in testdata:
answer = numpy.argmax(net.activate(row[1:]))
answerlist.append(answer)
tstresult = percentError(answerlist, [x[0] for x in testdata])
print "Test error: " + str(tstresult)