def test_read_variable_is_value_syntax(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 3) self.assertEqual(["a", "b", "c"], list(map(lambda x: x.name, table.domain.variables))) np.testing.assert_almost_equal(table.X.todense(), np.array([[1, 2, 3]]))
def test_sparse_basket(self): current_dir = os.path.dirname(__file__) dataset = os.path.join(current_dir, "iris_basket.basket") table = BasketReader().read_file(dataset) test = Orange.data.Table.from_table_rows(table, range(0, len(table), 2)) train = Orange.data.Table.from_table_rows(table, range(1, len(table), 2)) learn = DummyMulticlassLearner() clf = learn(train) p = clf(test) self.assertEqual(p.shape, test.Y.shape) p = clf(test.X) self.assertEqual(p.shape, test.Y.shape)
def test_handles_quote(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 4)
def test_handles_unicode(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 3) np.testing.assert_almost_equal(table.X.todense(), np.array([[1, 1, 1]]))
def test_variables_can_be_listed_in_any_order(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 3) np.testing.assert_almost_equal(table.X.todense(), np.array([[1, 1, 0], [1, 1, 1]]))
def test_handles_duplicate_variables(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 2) np.testing.assert_almost_equal(table.X.todense(), np.array([[3, 2]]))
def test_handles_spaces_between_variables(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 3) self.assertEqual(set(x for x in table[0]), {1, 2, 3})
def test_read_variable_only_syntax(self, fname): table = BasketReader().read_file(fname) self.assertEqual(len(table.domain.variables), 5) np.testing.assert_almost_equal(table.X.todense(), np.array([[1, 1, 1, 1, 1]]))
def read_basket(filename): return BasketReader(filename).read()