在对目标进行二值化时Pybrain TypeError

时间:2017-02-07 11:09:23

标签: python

我使用pybrain发出以下错误_convertToOneOfMany()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-95-f1c0d3ad67e6> in <module>()
 19 print y_train
 20 ds_train.setField('target', y_train[:, np.newaxis])
 ---> 21 ds_train._convertToOneOfMany( )
 22 

\pybrain\datasets\classification.pyc in _convertToOneOfMany(self, bounds)
140         newtarg = zeros([len(self), self.nClasses], dtype='Int32') + bounds[0]
141         for i in range(len(self)):
--> 142             newtarg[i, int(oldtarg[i])] = bounds[1]
143         self.setField('target', newtarg)
144         self.setField('class', oldtarg)

TypeError: don't know how to convert scalar number to int

我有70个班级(国家/地区名称),目标列表y_train如下所示:

[u'\u0418\u0442\u0430\u043b\u0438\u044f'
u'\u0420\u043e\u0441\u0441\u0438\u044f'
u'\u041c\u0430\u0440\u043e\u043a\u043a\u043e' ...,
u'\u041d\u0438\u0434\u0435\u0440\u043b\u0430\u043d\u0434\u044b'
u'\u0422\u0443\u0440\u0446\u0438\u044f'
u'\u0412\u044c\u0435\u0442\u043d\u0430\u043c'] 

可能是什么事?有办法解决吗?

1 个答案:

答案 0 :(得分:0)

对于那些面对同样的人:pybrain只需要整数类型的目标,所以你必须索引任何目标。