Error: PyBrain is used to construct a neural network.

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( )
Copy the code


\

Error:

AttributeError: ‘SupervisedDataSet’ object has no attribute ‘_convertToOneOfMany’\

Alldata is defined as a ClassificationDataSet in the code. After checking the official website, we found that this class does have a _convertToOneOfMany() method.

In github.com/pybrain/pyb… The reasons are as follows:

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.
Copy the code

This commit breaks polymorphism: When called on an ClassificationDataSet (as shown in the tutorials) it no longer returns ClassificationDataSets but SupervisedDataSets.\

perform

After splitWithProporion alldata returns SupervisedDataSets rather than ClassificationDataSet, but no SupervisedDataSets _convertToOneOfMany method.Copy the code
Copy the code
Solutions:Copy the code
http://stackoverflow.com/questions/27887936/attributeerror-using-pybrain-splitwithportion-object-type-changed/30869317#3 0869317Copy the code
Change the above code to:Copy the code
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] )Copy the code
Copy the code
s
Copy the code