lmjohns3 / theanets

Neural network toolkit for Python
http://theanets.rtfd.org
MIT License
328 stars 73 forks source link

Network object has no attribute cose #16

Closed kadarakos closed 10 years ago

kadarakos commented 10 years ago

This code runs but if I change the Regressor to Network I get the error message that the Network has no attribute cost. What am I doing wrong?

def getDataset():
    description_vectors = numpy.load('train_desps_features.npy')
    signature_vectors = numpy.load('train_signatures_features.npy')
    dataset = (description_vectors, signature_vectors)
    return dataset

def trainModel(dataset):
    input_layer = len(dataset[0][0])
    hidden1 = int(input_layer*(2.0/3))
    output_layer = len(dataset[1][0])
    e = theanets.Experiment(theanets.Regressor, layers=(input_layer, hidden1, output_layer))
    e.run(dataset, dataset)

dataset = getDataset()
trainModel(dataset)
kadarakos commented 10 years ago

The network also gives a very poor error rate error=93.2929

lmjohns3 commented 10 years ago

The code you posted looks correct at first glance. I'm curious how you could get an attribute error and still get some sort of error value -- usually an attribute error should halt the program.

Could you post the output from running this code?

kadarakos commented 10 years ago

Sorry I phrased, it the wrong way then. I don't get the attribute error if i use the theanets.Regressor class and the program runs and I get bad results. If I use the theantets.Network i get this

File "/usr/local/lib/python2.7/dist-packages/theanets/feedforward.py", line 328, in J cost = self.cost AttributeError: 'Network' object has no attribute 'cost'

lmjohns3 commented 10 years ago

Ah, yes. The Network class is abstract (it doesn't implement cost, among other things), so it won't work to use in an Experiment. I should probably make that more explicit. For your dataset, since you have explicit, continuous-valued output targets, you should be using Regressor.

As for the poor training error, training neural networks is something of a black art. There are a lot of different training methods (try optimize='cg' or optimize='hf', for instance), and several of the methods (but in particular SGD) have a lot of parameters that need tuning to get good training performance.

This has been a problem for several folks trying to use this library. (And, furthermore, it is a problem for people using neural networks in general!) I should write up some suggestions for training as part of the documentation. But as a general strategy, try different training methods, and also try setting the parameters for the training methods -- I've found that sampling randomly from a log-uniform distribution gets you a good idea of which parameter settings work well. There are also packages for selecting training parameters (see https://github.com/hyperopt/hyperopt for a good example).