I have written a program to train my network using pybrain. I have 104 inputs,and 7 outputs in each line of the train file.I have created one hidden layer with length of 50.The network is written in an .xml file.But I dont know how to write the final weights and biases in a file so that I can calculate precision and recall.Can anyone help?
from pybrain.datasets import SupervisedDataSet
from pybrain.datasets import ClassificationDataSet
from pybrain.utilities import percentError
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.modules import SoftmaxLayer
from pybrain.tools.xml.networkwriter import NetworkWriter
from pybrain.tools.xml.networkreader import NetworkReader
ds = SupervisedDataSet(104,7)
tf = open('neural_net_feature.txt','r')
for line in tf.readlines():
data = [float(x) for x in line.strip().split(',') if x != '']
indata = tuple(data[:104])
outdata = tuple(data[104:])
ds.addSample(indata,outdata)
n=buildNetwork(ds.indim,50,ds.outdim,hiddenclass=SigmoidLayer,outclass=SigmoidLayer)
NetworkWriter.writeToFile(n, 'filename.xml')
n = NetworkReader.readFrom('filename.xml')
t = BackpropTrainer(n,learningrate=0.01,momentum=0.5,verbose=True)
t.trainUntilConvergence(dataset=ds, maxEpochs=None, verbose=False , continueEpochs=10, validationProportion=0.10)
t.testOnData(verbose=True)
Thanks