AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'
来源:互联网 发布:如何访问网页数据库 编辑:程序博客网 时间:2024/06/07 17:46
使用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
(as shown in the tutorials) it no longer returns ClassificationDataSet
s but SupervisedDataSet
s.
执行
splitWithProporion后alldata返回的是SupervisedDataSet
s而不是ClassificationDataSet,而SupervisedDataSet
s没有_convertToOneOfMany方法。
解决办法:
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
1 0
- AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'
- AttributeError: 'classmethod' object has no attribute '__module__'
- AttributeError: 'module' object has no attribute 'getpass'
- AttributeError: ‘NoneType’ object has no attribute ‘clone’
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'NoneType' object has no attribute 'clone'
- AttributeError: 'tuple' object has no attribute 'Multi'
- AttributeError: 'Response' object has no attribute 'json'
- AttributeError: 'module' object has no attribute(转)
- AttributeError: 'Connection' object has no attribute 'connection_errors'
- AttributeError: 'module' object has no attribute 'randint'
- AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
- AttributeError: 'WebDriver' object has no attribute
- AttributeError: 'NoneType' object has no attribute
- AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'module' object has no attribute 'LabelMap'
- AttributeError: 'module' object has no attribute 'XXX'
- thinkPHP--Volist标签
- IOS 多种反向传值对比(代理,block,通知)
- ffmpeg源码分析二:main函数和transcode函数 (转2)
- Masonry 框架的使用
- Referenced file contains errors (xml文件第一行小红叉错误)
- AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'
- 对象的生灭——构造函数、拷贝构造函数、赋值构造函数和析构函数
- java语言基础(17)——方法(类中的函数)的使用及重载
- ffmpeg源码分析三:transcode_init函数 (转3)
- Qt中窗体控件按照比例缩放,自适应窗口大小进行布局
- Android 蓝牙开发之搜索、配对、连接、通信大全
- 小波和傅里叶变换之间关系详细讲解
- 常用工具类--仅针对于JAVA
- ffmpeg源码分析四:transcode_step函数 (转4)