本文整理汇总了Python中pybrain.utilities.percentError函数的典型用法代码示例。如果您正苦于以下问题:Python percentError函数的具体用法?Python percentError怎么用?Python percentError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了percentError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
def train(self):
print "Enter the number of times to train, -1 means train until convergence:"
t = int(raw_input())
print "Training the Neural Net"
print "self.net.indim = "+str(self.net.indim)
print "self.train_data.indim = "+str(self.train_data.indim)
trainer = BackpropTrainer(self.net, dataset=self.train_data, momentum=0.1, verbose=True, weightdecay=0.01)
if t == -1:
trainer.trainUntilConvergence()
else:
for i in range(t):
trainer.trainEpochs(1)
trnresult = percentError( trainer.testOnClassData(), self.train_data['class'])
# print self.test_data
tstresult = percentError( trainer.testOnClassData(dataset=self.test_data), self.test_data['class'] )
print "epoch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
if i % 10 == 0 and i > 1:
print "Saving Progress... Writing to a file"
NetworkWriter.writeToFile(self.net, self.path)
print "Done training... Writing to a file"
NetworkWriter.writeToFile(self.net, self.path)
return trainer
示例2: main
def main():
trndata, tstdata = createDS()
for repeat in xrange(repeats):
iter_trn_results = []
iter_tst_results = []
nn = createNNLong(trndata)
hiddenAstrocyteLayer, outputAstrocyteLayer = associateAstrocyteLayers(nn)
trainer = BackpropTrainer(nn, dataset=trndata, learningrate=0.01,
momentum=0.1, verbose=False, weightdecay=0.0)
for grand_iter in xrange(iterations):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(), trndata['class'])
iter_trn_results.append(trnresult)
tstresult = percentError(trainer.testOnClassData(dataset=tstdata), tstdata['class'])
iter_tst_results.append(tstresult)
if not grand_iter%20:
print 'epoch %4d' %trainer.totalepochs, 'train error %5.2f%%' %trnresult, \
'test error %5.2f%%' %tstresult
inputs = list(trndata['input'])
random.shuffle(inputs)
for inpt in trndata['input']:
nn.activate(inpt)
for minor_iter in range(hiddenAstrocyteLayer.astrocyte_processing_iters):
hiddenAstrocyteLayer.update()
outputAstrocyteLayer.update()
hiddenAstrocyteLayer.reset()
outputAstrocyteLayer.reset()
all_trn_results.append(iter_trn_results)
all_tst_results.append(iter_tst_results)
plotResults(all_trn_results)
plotResults(all_tst_results)
plt.show()
示例3: train
def train(self):
#self.init_iri()
self.init_image()
self.ds = ClassificationDataSet(self.IN, 1, nb_classes=128)
#classifier.init_image()
self.load_data()
print "Number of trianing patterns: ", len(self.trndata)
print "Input and output dimensions: ", self.trndata.indim, self.trndata.outdim
print "First sample (input, target, class):"
print self.trndata['input'][0], self.trndata['target'][0], self.trndata['class'][0]
print self.trndata.indim, self.trndata.outdim
self.net = buildNetwork(self.trndata.indim, 7, self.trndata.outdim)
trainer = BackpropTrainer(self.net, dataset=self.trndata, momentum=0.1, verbose=True, weightdecay=0.01)
"""
for i in range(200):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(), self.trndata['class'])
tstresult = percentError(trainer.testOnClassData(dataset = self.tstdata), self.tstdata["class"])
print "epch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
"""
trainer.trainUntilConvergence()
trnresult = percentError(trainer.testOnClassData(), self.trndata['class'])
tstresult = percentError(trainer.testOnClassData(dataset = self.tstdata), self.tstdata["class"])
print "epch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
示例4: testBPHasLearned
def testBPHasLearned(self):
trnresult = percentError(self.trainer.testOnClassData(),
self.trn_d['class'])
tstresult = percentError(self.trainer.testOnClassData(dataset=self.tst_d),
self.tst_d['class'])
print 'trn perc error', trnresult
print 'tst perc error', tstresult
示例5: calculateANNaccuracy
def calculateANNaccuracy(model, trndata, tstdata, trainer,iterations=20,maxEpochs=10):
trn_sum=0
tst_sum=0
trnfinal=[]
tstfinal=[]
for i in range(iterations):
trainer.trainUntilConvergence(maxEpochs=maxEpochs, continueEpochs=1)
trnresult = percentError( trainer.testOnClassData(),
trndata['class'] )
tstresult = percentError( trainer.testOnClassData(
dataset=tstdata ), tstdata['class'] )
trnres=100-trnresult
tstres=100-tstresult
trn_sum=trn_sum+trnres
tst_sum=tst_sum+tstres
trnfinal.append(trnres)
tstfinal.append(tstres)
trn_avg=trn_sum/(i+1)
tst_avg=tst_sum/(i+1)
print "Train average accuracy: %5.2f%%" % trn_avg
print "Test average accuracy: %5.2f%%" % tst_avg
print "Train SD = ", np.std(trnfinal)
print "Test SD = ", np.std(tstfinal)
print "\n"
return tst_avg
示例6: trainNetwork
def trainNetwork(self,proportion = 0):
if proportion != 0:
tstdata, trndata = self.alldata.splitWithProportion( 0.01*proportion )
else:
trndata = self.alldata
trndata._convertToOneOfMany( )
if proportion != 0:
tstdata._convertToOneOfMany( )
print "Number of training patterns: ", len(trndata)
print "Input and output dimensions: ", trndata.indim, trndata.outdim
self.fnn = buildNetwork( trndata.indim, self.hidden_layer_size, trndata.outdim,
hiddenclass=SigmoidLayer,outclass=SoftmaxLayer )
self.trainer = BackpropTrainer( self.fnn, dataset=trndata, momentum=0.1, verbose=True, weightdecay=0.01)
for i in range(self.iterations_number):
self.trainer.trainEpochs( 1 )
trnresult = percentError( self.trainer.testOnClassData(),
trndata['class'] )
if proportion != 0:
tstresult = percentError( self.trainer.testOnClassData(
dataset=tstdata ), tstdata['class'] )
if proportion != 0:
print "epoch: %4d" % self.trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
else:
print "epoch: %4d" % self.trainer.totalepochs, \
" train error: %5.2f%%" % trnresult
示例7: main
def main():
images, labels = load_labeled_training(flatten=True)
images = standardize(images)
# images, labels = load_pca_proj(K=100)
shuffle_in_unison(images, labels)
ds = ClassificationDataSet(images.shape[1], 1, nb_classes=7)
for i, l in zip(images, labels):
ds.addSample(i, [l - 1])
# ds._convertToOneOfMany()
test, train = ds.splitWithProportion(0.2)
test._convertToOneOfMany()
train._convertToOneOfMany()
net = shortcuts.buildNetwork(train.indim, 1000, train.outdim, outclass=SoftmaxLayer)
trainer = BackpropTrainer(net, dataset=train, momentum=0.1, learningrate=0.01, weightdecay=0.05)
# trainer = RPropMinusTrainer(net, dataset=train)
# cv = validation.CrossValidator(trainer, ds)
# print cv.validate()
net.randomize()
tr_labels_2 = net.activateOnDataset(train).argmax(axis=1)
trnres = percentError(tr_labels_2, train["class"])
# trnres = percentError(trainer.testOnClassData(dataset=train), train['class'])
testres = percentError(trainer.testOnClassData(dataset=test), test["class"])
print "Training error: %.10f, Test error: %.10f" % (trnres, testres)
print "Iters: %d" % trainer.totalepochs
for i in range(100):
trainer.trainEpochs(10)
trnres = percentError(trainer.testOnClassData(dataset=train), train["class"])
testres = percentError(trainer.testOnClassData(dataset=test), test["class"])
trnmse = trainer.testOnData(dataset=train)
testmse = trainer.testOnData(dataset=test)
print "Iteration: %d, Training error: %.5f, Test error: %.5f" % (trainer.totalepochs, trnres, testres)
print "Training MSE: %.5f, Test MSE: %.5f" % (trnmse, testmse)
示例8: train
def train(args):
inputs, ys, gc = args
row_length = len(inputs[0])
d = ds.ClassificationDataSet(
row_length, nb_classes=2, class_labels=['Poisonous',
'Edible'])
d.setField('input', inputs)
d.setField('target', ys)
test, train = d.splitWithProportion(.25)
test._convertToOneOfMany()
train._convertToOneOfMany()
hidden = row_length // 2
print "indim:", train.indim
net = buildNetwork(train.indim,
hidden,
train.outdim,
outclass=SoftmaxLayer)
trainer = BackpropTrainer(net,
dataset=train,
momentum=0.0,
learningrate=0.1,
verbose=True,
weightdecay=0.0)
for i in xrange(20):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(),
train['class'])
tstresult = percentError(
trainer.testOnClassData(dataset=test),
test['class'])
print "epoch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
return net, gc
示例9: calculateANNaccuracy
def calculateANNaccuracy(model, trndata, tstdata, trainer):
trn_sum=0
tst_sum=0
trnfinal=[]
tstfinal=[]
for i in range(20):
trainer.trainUntilConvergence(maxEpochs=10, continueEpochs=3, validationProportion=0.30)
trnresult = percentError( trainer.testOnClassData(),
trndata['class'] )
tstresult = percentError( trainer.testOnClassData(
dataset=tstdata ), tstdata['class'] )
trnres=100-trnresult
tstres=100-tstresult
trn_sum=trn_sum+trnres
tst_sum=tst_sum+tstres
trnfinal.append(trnres)
tstfinal.append(tstres)
trn_avg=trn_sum/(i+1)
tst_avg=tst_sum/(i+1)
'''
print "Test average accuracy: %5.2f%%" % tst_avg
print "Test SD = ", np.std(tstfinal)
'''
return tst_avg
示例10: drawPic
def drawPic():
try:
sampleCount = int(inputEntry.get())
except:
sampleCount = 50
print 'Enter an integer.'
inputEntry.delete(0, END)
inputEntry.insert(0, '50')
# Need column vectors in dataset, not arrays
for i in range(sampleCount):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(), trndata['class'])
tstresult = percentError(trainer.testOnClassData(dataset=tstdata), tstdata['class'])
if i % 20 == 0:
t.delete(1.0, END)
t.insert(END, "epoch:" + str(trainer.totalepochs) + " train error:" + str(round(trnresult, 2)) \
+ "% test error:" + str(round(tstresult, 2)) + "%\n")
# Clear the Figure
drawPic.f.clf()
drawPic.a = drawPic.f.add_subplot(111, projection='3d')
drawPic.a.set_title('Training...')
for a, c, m in [(0, 'r', 'o'), (1, 'b', '^'), (2, 'y', 's')]:
out = fnn.activateOnDataset(alldata)
out = out.argmax(axis=1)
here = (out == a)
drawPic.a.scatter(alldata['input'][here, 0], alldata['input'][here, 1], alldata['input'][here, 2], c=c, marker=m)
drawPic.canvas.show()
示例11: measuredLearning
def measuredLearning(ds):
trndata,tstdata = splitData(ds,.025)
#build network
###
# This network has no hidden layters, you might need to add some
###
fnn = buildNetwork( trndata.indim, 22, trndata.outdim, outclass=SoftmaxLayer )
trainer = BackpropTrainer( fnn, verbose=True,dataset=trndata)
####
# Alter this to figure out how many runs you want. Best to start small and be sure that you see learning.
# Before you ramp it up.
###
for i in range(150):
trainer.trainEpochs(5)
trnresult = percentError(trainer.testOnClassData(),trndata['class'] )
tstresult = percentError( trainer.testOnClassData(
dataset=tstdata ), tstdata['class'] )
print "epoch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
if(trnresult<.5):
return
示例12: trainStep
def trainStep(fnn, trainer, trndata, tstdata):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(), trndata["class"])
tstresult = percentError(trainer.testOnClassData(dataset=tstdata), tstdata["class"])
print "epoch: %4d" % trainer.totalepochs, " train error: %5.2f%%" % trnresult, " test error: %5.2f%%" % tstresult
out = fnn.activateOnDataset(griddata)
out = out.argmax(axis=1) # the highest output activation gives the class
out = out.reshape(X.shape)
figure(1)
ioff() # interactive graphics off
clf() # clear the plot
hold(True) # overplot on
for c in [0, 1, 2]:
here, _ = where(trndata["class"] == c)
plot(trndata["input"][here, 0], trndata["input"][here, 1], "o")
if out.max() != out.min(): # safety check against flat field
contourf(X, Y, out) # plot the contour
ion() # interactive graphics on
draw() # update the plot
figure(2)
ioff() # interactive graphics off
clf() # clear the plot
hold(True) # overplot on
for c in [0, 1, 2]:
here, _ = where(tstdata["class"] == c)
plot(tstdata["input"][here, 0], tstdata["input"][here, 1], "o")
if out.max() != out.min(): # safety check against flat field
contourf(X, Y, out) # plot the contour
ion() # interactive graphics on
draw() # update the plot
示例13: test
def test(self,filename,classes,trainer,net):
testLabels = []
#load test data
tstdata = ClassificationDataSet(103, 1, nb_classes=classes)
tstdata = self.loaddata(filename, classes)
testLabels = tstdata['target'];
# some sort of mandatory conversion
tstdata._convertToOneOfMany()
# using numpy array
output = np.array([net.activate(x) for x, _ in tstdata])
output = output.argmax(axis=1)
print(output)
print("on test data",percentError( output, tstdata['class'] ))
for i, l in enumerate(output):
print l, '->', testLabels[i][0]
# alternate version - using activateOnDataset function
out = net.activateOnDataset(tstdata).argmax(axis=1)
print out
return percentError( out, tstdata['class'])
示例14: createnetwork
def createnetwork(n_hoglist,n_classlist,n_classnum,n_hiddensize=100):
n_inputdim=len(n_hoglist[0])
n_alldata = ClassificationDataSet(n_inputdim,1, nb_classes=n_classnum)
for i in range(len(n_hoglist)):
n_input = n_hoglist[i]
n_class = n_classlist[i]
n_alldata.addSample(n_input, [n_class])
n_tstdata, n_trndata = n_alldata.splitWithProportion( 0.25 )
n_trndata._convertToOneOfMany( )
n_tstdata._convertToOneOfMany( )
print "Number of training patterns: ", len(n_trndata)
print "Input and output dimensions: ", n_trndata.indim, n_trndata.outdim
print "First sample (input, target, class):"
print n_trndata['input'][0], n_trndata['target'][0], n_trndata['class'][0]
n_fnn = buildNetwork(n_trndata.indim,n_hiddensize, n_trndata.outdim, outclass=SoftmaxLayer)
n_trainer = BackpropTrainer(n_fnn, dataset=n_trndata, momentum=0.1, verbose=True, weightdecay=0.01)
n_result = 1
while n_result > 0.1:
print n_result
n_trainer.trainEpochs(1)
n_trnresult = percentError(n_trainer.testOnClassData(),
n_trndata['class'])
n_tstresult = percentError(n_trainer.testOnClassData(
dataset=n_tstdata), n_tstdata['class'])
print "epoch: %4d" % n_trainer.totalepochs, \
" train error: %5.2f%%" % n_trnresult, \
" test error: %5.2f%%" % n_tstresult
n_result = n_tstresult
示例15: trainNetwork
def trainNetwork(inData, numOfSamples, numOfPoints, epochs):
# Build the dataset
alldata = createRGBdataSet(inData, numOfSamples, numOfPoints)
# Split into test and training data
trndata, tstdata = splitData(alldata)
# Report stats
print "Number of training patterns: ", len(trndata)
print "Input and output dimensions: ", trndata.indim, trndata.outdim
print "First sample (input, target, class):"
print trndata['input'][0], trndata['target'][0], trndata['class'][0]
# Build and train the network
fnn = buildNetwork( trndata.indim, 256, trndata.outdim, outclass=SoftmaxLayer )
trainer = BackpropTrainer( fnn, dataset=trndata, momentum=0.001, verbose=True, weightdecay=0.001)
#trainer.trainEpochs( epochs )
trainer.trainUntilConvergence(maxEpochs=epochs)
# Report results
trnresult = percentError( trainer.testOnClassData(), trndata['class'] )
tstresult = percentError( trainer.testOnClassData( dataset=tstdata ), tstdata['class'] )
print "epoch: %4d" % trainer.totalepochs, \
" train error: %5.2f%%" % trnresult, \
" test error: %5.2f%%" % tstresult
# Report results of final network
checkNeuralNet(trainer, alldata, numOfSamples)
return fnn