Assert Error when training perceptron

1,237 views
Skip to first unread message

Jake Cowton

unread,
Nov 14, 2014, 2:53:36 PM11/14/14
to py-ne...@googlegroups.com
I have the following data:

training_data = [[0.0, 0.0, 0.9999824999999999],
[0.0, 0.0, 0.9999824999999999],
[0.0, 0.0, 0.7529279999999999],
[0.9529245, 0.31372, 0.23136849999999998],
[0.9999824999999999, 0.0, 0.3019555],
[0.3019555, 0.36469949999999995, 0.7450849999999999],
[0.9999824999999999, 0.38430699999999995, 0.3490135],
[0.815672, 0.0, 0.19215349999999998],
[0.2627405, 0.05882249999999999, 0.8235149999999999],
[0.321563, 0.45881549999999993, 0.682341],
[0.658812, 0.164703, 0.3490135],
[0.972532, 0.31372, 0.26666199999999995],
[0.501952, 0.31372, 0.9999824999999999],
[0.894102, 0.41175749999999994, 0.45489399999999997]]

targets = [1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0]

I run:

In [1]: net = nl.net.newp([[0, 1], [0, 1], [0, 1]], 1)
In [2]: net.train(training_data, target, epochs=500, show=10, lr=0.1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-2-c3b69c18ac19> in <module>()
----> 1 net.train(training_data, target, epochs=500, show=10, lr=0.1)

/home/jake/.virtualenvs/ai/lib/python2.7/site-packages/neurolab/core.pyc in train(self, *args, **kwargs)
    163 
    164         """
--> 165         return self.trainf(self, *args, **kwargs)
    166 
    167     def reset(self):

/home/jake/.virtualenvs/ai/lib/python2.7/site-packages/neurolab/core.pyc in __call__(self, net, input, target, **kwargs)
    324         if target is not None:
    325             target = np.asfarray(target)
--> 326             assert target.ndim == 2
    327             assert target.shape[1] == net.co
    328             assert target.shape[0] == input.shape[0]

AssertionError: 

In [3]: 

Any idea what's going on here? Because the error message it's helping so much :P

test.py

Evgeny Zuev

unread,
Nov 16, 2014, 11:34:03 PM11/16/14
to py-ne...@googlegroups.com
Bad target data format:
need:
targets = [[1], [1], [1], [0] ... [0]]

Ratna

unread,
Apr 26, 2018, 2:44:37 AM4/26/18
to NeuroLab
I have the same problem, Could you please tell me how did you resolve this issue.
Reply all
Reply to author
Forward
0 new messages