Reputation: 1353
I am trying to set up a neural network in Python (using PyBrain) for prediction purposes. I already set one up with a small, mock dataset, but when expanding this network to work for larger datasets, I run into an issue regarding an AssertionError. Here is my code:
ds = ClassificationDataSet(231, 1)
for x in range(inputData[0].size):
ds.addSample(inputData[:,x], inputAnswers[x])
network = buildNetwork(191, 128, 1, bias=True, hiddenclass=TanhLayer)
network.randomize()
trainer = BackpropTrainer(network)
trainer.setData(ds)
and here is the error message I receive:
File "ANN_rawData.py", line 45, in <module>
trainer.setData(ds)
File "[path]", line 22, in setData
assert dataset.indim == self.module.indim
AssertionError
What does this error mean, and how could I fix it? Thank you in advance!
Upvotes: 2
Views: 2811
Reputation: 7691
The assert statement checks if a condition is true. In this case, if the inner dimension (indim
) of your network
is the same as your dataset, ds
. Because they aren't, the error is raised:
>>> ds = ClassificationDataSet(231, 1)
>>> network = buildNetwork(191, 128, 1, bias=True)
>>> assert ds.indim == network.indim # 231 != 191, error!
AssertionError
To fix it:
Make sure that your network
and ds
have the same inner dimensions, as for example:
>>> ds = ClassificationDataSet(191, 1)
>>> network = buildNetwork(191, 128, 1, bias=True)
>>> assert ds.indim == network.indim # 191 == 191, okay!
Upvotes: 4
Reputation: 126
The assert statement checks a condition and returns a boolean value. The AssertionError is telling you that the result of assert dataset.indim == self.module.indim was false, putting the code in error, thus returning the Assertion error. If this is an expected condition for the code you are inputting, catch the exception and continue.
Upvotes: -3