使用 pyBrain _splitWithPortion 的 AttributeError - 对象类型已更改?

2024-03-11

我正在按照基本分类教程测试 pybrainhere http://pybrain.org/docs/tutorial/datasets.html#classificationdataset以及一些更现实的数据的不同看法here http://corpocrat.com/2014/10/10/tutorial-pybrain-neural-network-for-classifying-olivetti-faces/。但是,我在应用 trndata._convertToOneOfMany() 时收到此错误:

AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany

数据集被创建为classification.ClassificationDataSet对象,但是调用splitWithProportion似乎会更改它的supervised.SupervisedDataSet对象,因此对于Python来说这个错误似乎并不令人惊讶,因为supervised.SupervisedDataSet没有该方法, classification.ClassificationDataSet 可以。代码在这里 https://github.com/pybrain/pybrain/blob/master/pybrain/datasets/classification.py.

然而,在如此多的教程中使用了相同的代码,我觉得我一定错过了一些东西,因为很多其他人都在使用它。我查看了 github 上代码库的更改,发现这个函数没有任何变化,我也尝试过在 Python 3 和 2.7 下运行,但没有区别。如果有人有任何指示让我回到正确的道路上,我将非常感激。

#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()

我有同样的问题。我添加了以下代码以使其在我的机器上运行。

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

这转换tstdata and trndata回到ClassificationDataSet type.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 pyBrain _splitWithPortion 的 AttributeError - 对象类型已更改? 的相关文章

随机推荐