使用pyBrain _splitWithPortion的AttributeError-对象类型已更改? [英] AttributeError using pyBrain _splitWithPortion - object type changed?

查看:141
本文介绍了使用pyBrain _splitWithPortion的AttributeError-对象类型已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照基本分类教程此处进行pybrain的测试,并对它进行另一种处理此处.但是,当应用带有以下错误的trndata._convertToOneOfMany()时,我会收到此错误:

I'm testing out pybrain following the basic classification tutorial here and a different take on it with some more realistic data here. However I receive this error when applying trndata._convertToOneOfMany() with the error:

AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany

数据集被创建为一个分类.ClassificationDataSet对象,但是调用splitWithProportion似乎将其更改为supervised.SupervisedDataSet对象,因此对于Python来说,这个错误似乎并不像supervised.SupervisedDataSet那样令人惊讶该方法,classification.ClassificationDataSet可以. 此处的代码.

The data set is created as a classification.ClassificationDataSet object however calling splitWithProportion seems to change it supervised.SupervisedDataSet object, so being fairly new to Python this error doesn't seem such a surprise as the supervised.SupervisedDataSet doesn't have that method, classification.ClassificationDataSet does. Code here.

但是,在许多教程中都使用了相同的确切代码,我觉得我必须丢失一些东西,因为其他许多人都在使用它.我已经看过对github上代码库的更改,并且此功能周围没有任何东西,我也尝试过在Python 3 vs 2.7下运行,但没有区别.如果有人能带我回到正确的道路,那将不胜感激.

However the same exact code is used across so many tutorials I feel that I must be missing something as plenty of other people have it working. I've looked at changes to the codebase on github and there's nothing around this function, I've also tried running under Python 3 vs 2.7 but no difference. If anyone has any pointers to get me back on the right path and that would be very much appreciated.

#flatten the 64x64 data in to one dimensional 4096
ds = ClassificationDataSet(4096, 1 , nb_classes=40)
for k in xrange(len(X)): #length of X is 400
    ds.addSample(np.ravel(X[k]),y[k])
    # a new sample consisting of input and target

print(type(ds))      
tstdata, trndata = ds.splitWithProportion( 0.25 )
print(type(trndata))

trndata._convertToOneOfMany()
tstdata._convertToOneOfMany()

推荐答案

我遇到了同样的问题.我添加了以下代码以使其在我的计算机上正常工作.

I had the same problem. I added the following code to make it work on my machine.

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] )

这会将tstdatatrndata转换回ClassificationDataSet类型.

这篇关于使用pyBrain _splitWithPortion的AttributeError-对象类型已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆