def testLoadData(self): testPoints = [[0.307143, 0.130137, 0.050000], [0.365584, 0.105479, 0.050000], [0.178571, 0.201027, 0.050000], [0.272078, 0.145548, 0.050000], [0.318831, 0.065411, 0.050000], [0.190260, 0.086986, 0.050000], [0.190260, 0.062329, 0.072500], [0.120130, 0.068493, 0.072500], [0.225325, 0.056164, 0.072500], [0.213636, 0.050000, 0.072500]] testValues = [ -1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, -1.000000, -1.000000, -1.000000, -1.000000 ] filename = pathlocal + '/datasets/liver-disorders_normalized.arff.gz' adapter = ARFFAdapter(filename) container = adapter.loadData() points = container.getPoints() values = container.getValues() size = len(testPoints) dim = len(testPoints[0]) testVector = DataVector(dim) for rowIdx in xrange(size): points.getRow(rowIdx, testVector) for colIdx in xrange(dim): if cvar.USING_DOUBLE_PRECISION: self.assertEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) else: self.assertAlmostEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) self.assertEqual(values[rowIdx], testValues[rowIdx])
def testLoadData(self): testPoints = [[0.307143,0.130137,0.050000], [0.365584,0.105479,0.050000], [0.178571,0.201027,0.050000], [0.272078,0.145548,0.050000], [0.318831,0.065411,0.050000], [0.190260,0.086986,0.050000], [0.190260,0.062329,0.072500], [0.120130,0.068493,0.072500], [0.225325,0.056164,0.072500], [0.213636,0.050000,0.072500] ] testValues = [-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, -1.000000, -1.000000, -1.000000, -1.000000] filename = pathlocal + '/datasets/liver-disorders_normalized.arff.gz' adapter = ARFFAdapter(filename) container = adapter.loadData() points = container.getPoints() values = container.getValues() size = len(testPoints) dim = len(testPoints[0]) testVector = DataVector(dim) for rowIdx in xrange(size): points.getRow(rowIdx, testVector) for colIdx in xrange(dim): if cvar.USING_DOUBLE_PRECISION: self.assertEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) else: self.assertAlmostEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) self.assertEqual(values[rowIdx], testValues[rowIdx])
def testSave(self): filename = pathlocal + '/datasets/saving.arff.gz' testPoints = [[0.307143, 0.130137, 0.050000], [0.365584, 0.105479, 0.050000], [0.178571, 0.201027, 0.050000], [0.272078, 0.145548, 0.050000], [0.318831, 0.065411, 0.050000], [0.190260, 0.086986, 0.050000], [0.190260, 0.062329, 0.072500], [0.120130, 0.068493, 0.072500], [0.225325, 0.056164, 0.072500], [0.213636, 0.050000, 0.072500]] testValues = [ -1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, -1.000000, -1.000000, -1.000000, -1.000000 ] attributes = { "x0": "NUMERIC", "x1": "NUMERIC", "x2": "NUMERIC", "class": "NUMERIC", } size = len(testPoints) dim = len(testPoints[0]) point = DataVector(dim) points = DataMatrix(size, dim) for row in xrange(size): for col in xrange(dim): point[col] = testPoints[row][col] points.setRow(row, point) adapter = ARFFAdapter(filename) adapter.save(points, testValues, attributes) (points, values) = adapter.loadData().getPointsValues() size = len(testPoints) dim = len(testPoints[0]) testVector = DataVector(dim) for rowIdx in xrange(size): points.getRow(rowIdx, testVector) for colIdx in xrange(dim): if cvar.USING_DOUBLE_PRECISION: self.assertEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) else: self.assertAlmostEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) self.assertEqual(values[rowIdx], testValues[rowIdx]) os.remove(filename)
def withTestingDataFromARFFFile(self, filename): """ Signals to use data from ARFF file for testing dataset @param filename: Filename where to read the data from @return: LearnerBuilder object itself """ adapter = ARFFAdapter(filename) dataContainer = adapter.loadData(DataContainer.TEST_CATEGORY) if self._learner.dataContainer is not None: dataContainer = self._learner.dataContainer.combine(dataContainer) self._learner.setDataContainer(dataContainer) else: self._learner.setDataContainer(dataContainer) return self
def withTestingDataFromARFFFile(self, filename): """ Signals to use data from ARFF file for testing dataset @param filename: Filename where to read the data from @return: LearnerBuilder object itself """ adapter = ARFFAdapter(filename) dataContainer = adapter.loadData(DataContainer.TEST_CATEGORY) if self._learner.dataContainer is not None: dataContainer = self._learner.dataContainer.combine(dataContainer) self._learner.setDataContainer(dataContainer) else: self._learner.setDataContainer(dataContainer) return self
def testSave(self): filename = pathlocal + '/datasets/saving.arff.gz' testPoints = [[0.307143,0.130137,0.050000], [0.365584,0.105479,0.050000], [0.178571,0.201027,0.050000], [0.272078,0.145548,0.050000], [0.318831,0.065411,0.050000], [0.190260,0.086986,0.050000], [0.190260,0.062329,0.072500], [0.120130,0.068493,0.072500], [0.225325,0.056164,0.072500], [0.213636,0.050000,0.072500] ] testValues = [-1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, -1.000000, -1.000000, -1.000000, -1.000000] attributes = { "x0":"NUMERIC", "x1":"NUMERIC", "x2":"NUMERIC", "class":"NUMERIC", } size = len(testPoints) dim = len(testPoints[0]) point = DataVector(dim) points = DataMatrix(size, dim) for row in xrange(size): for col in xrange(dim): point[col] = testPoints[row][col] points.setRow(row, point) adapter = ARFFAdapter(filename) adapter.save(points, testValues, attributes) (points, values) = adapter.loadData().getPointsValues() size = len(testPoints) dim = len(testPoints[0]) testVector = DataVector(dim) for rowIdx in xrange(size): points.getRow(rowIdx, testVector) for colIdx in xrange(dim): if cvar.USING_DOUBLE_PRECISION: self.assertEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) else: self.assertAlmostEqual(testVector[colIdx], testPoints[rowIdx][colIdx]) self.assertEqual(values[rowIdx], testValues[rowIdx]) os.remove(filename)