AttributeError using pyBrain _splitWithPortion - object type changed?

前端 未结 6 890
遥遥无期
遥遥无期 2021-02-07 06:36

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 applyi

6条回答
  •  遇见更好的自我
    2021-02-07 07:21

    I tried the suggested workaround from Muhammed Miah, but I still was tripped up when running the tutorial at the line:

    print( trndata['input'][0], trndata['target'][0], trndata['class'][0])
    

    trndata['class'] was an empty array, so index [0] threw a fault.

    I was able to workaround by making my own function ConvertToOneOfMany:

    def ConvertToOneOfMany(d,nb_classes,bounds=(0,1)):
      d2 = ClassificationDataSet(d.indim, d.outdim, nb_classes=nb_classes)
      for n in range(d.getLength()):
        d2.addSample( d.getSample(n)[0], d.getSample(n)[1] )
      oldtarg=d.getField('target')
      newtarg=np.zeros([len(d),nb_classes],dtype='Int32')+bounds[0]
      for i in range(len(d)):
        newtarg[i,int(oldtarg[i])]=bounds[1]
      d2.setField('class',oldtarg)
      d2.setField('target',newtarg)
      return(d2)
    

提交回复
热议问题