AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'
2017-03-11 22:40
686 查看
使用pybrain构造神经网络,在执行官网代码时出错:means = [(-1,0),(2,4),(3,1)]cov = [diag([1,1]), diag([0.5,1.2]), diag([1.5,0.7])]alldata = ClassificationDataSet(2, 1, nb_classes=3)for n in xrange(400):for klass in range(3):input = multivariate_normal(means[klass],cov[klass])alldata.addSample(input, [klass])tstdata, trndata = alldata.splitWithProportion( 0.25 )trndata._convertToOneOfMany( )tstdata._convertToOneOfMany( )报错:AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'在代码中alldata被定义成ClassificationDataSet,官网查看后发现这个类确实有_convertToOneOfMany()方法。在https://github.com/pybrain/pybrain/commit/2f02b8d9e4e9d6edbc135a355ab387048a00f1af中找到原因如下:
Now splitWithProporion uses numpy array indicies with numpy.random.permutation instead of for loop, before this change on large datasets this method was very slow, now its finish almost instant.This commit breaks polymorphism: When called on an
ClassificationDataSet(asshown in the tutorials) it no longer returns
ClassificationDataSetsbut
SupervisedDataSets.执行
splitWithProporion后alldata返回的是[code]SupervisedDataSets而不是ClassificationDataSet,而
SupervisedDataSets没有_convertToOneOfMany方法。[/code]
解决办法:
http://stackoverflow.com/questions/27887936/attributeerror-using-pybrain-splitwithportion-object-type-changed/30869317#30869317
将上面代码改为:
tstdata_temp, trndata_temp = alldata.splitWithProportion(0.25)tstdata = ClassificationDataSet(2, 1, nb_classes=3)for n in xrange(0, tstdata_temp.getLength()):tstdata.addSample( tstdata_temp.getSample(n)[0], tstdata_temp.getSample(n)[1] )trndata = ClassificationDataSet(2, 1, nb_classes=3)for n in xrange(0, trndata_temp.getLength()):trndata.addSample( trndata_temp.getSample(n)[0], trndata_temp.getSample(n)[1] )
s
相关文章推荐
- AttributeError: 'WebDriver' object has no attribute 'switchTo' 解决方法
- AttributeError: 'NoneType' object has no attribute 'clone'
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- python django AttributeError: 'QuerySet' object has no attribute '_meta'
- [置顶] AttributeError: 'module' object has no attribute '_base' 可行解决办法
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- AttributeError: 'dict' object has no attribute 'iteritems'
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- web.py 启动时候出现AttributeError: 'module' object has no attribute 'inet_pton'错误
- AttributeError: 'google.protobuf.py ***' object has no attribute '_value'
- AttributeError: 'module' object has no attribute 'text_format'
- AttributeError: 'module' object has no attribute 'face' 问题解决 opencv+python
- 关于AttributeError:'numpy.ndarray' object has no attribute 'index'
- 使用vectorizer.fit_transform时出现AttributeError: 'file' object has no attribute 'lower'
- AttributeError: 'Tensor' object has no attribute '_keras_history'
- AttributeError: 'dict' object has no attribute 'iteritems'
- AttributeError: ‘module’ object has no attribute’ 问题
- AttributeError: 'module' object has no attribute 'text_format'
- 【编程语言】PySpark 异常 AttributeError: 'PipelinedRDD' object has no attribute 'toDF'
- python “AttributeError: '_csv.reader' object has no attribute'next'” 报错的解决办法