Esempio n. 1
0
 def convertInstanceNominal(self, instance: Instance):
     if not self.m_needToTransform:
         self.push(instance, False)
         return
     vals = [0] * self.outputFormatPeek().numAttributes()
     attSoFar = 0
     for j in range(self.getInputFormat().numAttributes()):
         att = self.getInputFormat().attribute(j)
         if not att.isNominal() or j == self.getInputFormat().classIndex():
             vals[attSoFar] = instance.value(j)
             attSoFar += 1
         else:
             if att.numValues() <= 2 and not self.m_TransformAll:
                 vals[attSoFar] = instance.value(j)
                 attSoFar += 1
             else:
                 if instance.isMissing(j):
                     for k in range(att.numValues()):
                         vals[attSoFar + k] = instance.value(j)
                 else:
                     for k in range(att.numValues()):
                         if k == int(instance.value(j)):
                             vals[attSoFar + k] = 1
                         else:
                             vals[attSoFar + k] = 0
                 attSoFar += att.numValues()
     inst = Instance(instance.weight(), vals)
     self.copyValues(inst, False, instance.dataset(),
                     self.outputFormatPeek())
     self.push(inst)