def __init__(self, filename=None): SupervisedDataSet.__init__(self, 0, 0) self.nCls = 0 self.nSamples = 0 self.classHist = {} self.filename = '' if filename is not None: self.loadData(filename)
def _setDataFields(self, x, y): if not len(x): raise Exception("no input data found") SupervisedDataSet.__init__(self, len(x[0]), 1) self.setField('input', x) self.setField('target', y) flat_labels = list(self.getField('target').flatten()) classes = list(set(flat_labels)) self._classes = classes self.nClasses = len(classes) for class_ in classes: self.classHist[class_] = flat_labels.count(class_)
def __init__(self, inp, target=1, nb_classes=0, class_labels=None): """Initialize an empty dataset. `inp` is used to specify the dimensionality of the input. While the number of targets is given by implicitly by the training samples, it can also be set explicity by `nb_classes`. To give the classes names, supply an iterable of strings as `class_labels`.""" # FIXME: hard to keep nClasses synchronized if appendLinked() etc. is used. SupervisedDataSet.__init__(self, inp, target) self.addField('class', 1) self.nClasses = nb_classes if len(self) > 0: # calculate class histogram, if we already have data self.calculateStatistics() self.convertField('target', int) if class_labels is None: self.class_labels = list(set(self.getField('target').flatten())) else: self.class_labels = class_labels # copy classes (may be changed into other representation) self.setField('class', self.getField('target'))