class ScenarioTest(unittest.TestCase): def setUp(self): self.scenario = Scenario(cheat=False, verbose=False) def test_read_data(self): train_x, train_y = self.scenario.read_data('data/train.csv') test_x, test_y = self.scenario.read_data('data/test.csv') self.assertEqual(train_x.shape, (120, 4)) self.assertEqual(train_y.shape, (120, 1)) self.assertEqual(test_x.shape, (30, 4)) self.assertEqual(test_y.shape, (30, 1)) def test_evaluate(self): test_y = np.array([0, 1, 1, 2]) pred_y = np.array([0, 0, 1, 2]) self.assertEqual(0.75, self.scenario.evaluate(test_y, pred_y))
class ScenarioTest(unittest.TestCase): def setUp(self): self.scenario = Scenario(cheat=False, verbose=False) def test_read_data(self): train_data = self.scenario.read_data('data/train.csv') test_data = self.scenario.read_data('data/test.csv') self.assertEqual((10, 2), train_data.shape) self.assertEqual((5, 2), test_data.shape) def test_evaluate(self): test_y = np.array([1, 0, 0, 0]) pred_y = np.array([0, 1, 0, 0]) self.assertEqual(0.5, self.scenario.evaluate(test_y, pred_y)) def test_baseline(self): train_data = np.array([[0, 0], [10, 1]]) predict = self.scenario.baseline(train_data) self.assertEqual(0, predict(3)) self.assertEqual(1, predict(7))
class ScenarioTest(unittest.TestCase): def setUp(self): self.scenario = Scenario(cheat=False, verbose=False) self.scenario.n_user = 2 self.scenario.n_item = 2 def test_read_data(self): train_data = self.scenario.read_data('data/train.csv') test_data = self.scenario.read_data('data/test.csv') self.assertEqual((75000, 3), train_data.shape) self.assertEqual((25000, 3), test_data.shape) def test_data2matrix(self): data = [(1, 1, 1), (1, 2, 1), (2, 1, 1)] matrix = self.scenario.data2matrix(data) self.assertEqual(0, (matrix - np.array([[1, 1], [1, 0]])).sum()) def test_evaluate(self): test_matrix = np.array([[1, 1], [1, 0]]) pred_matrix = np.array([[0, 0], [0, 1]]) self.assertEqual(1, self.scenario.evaluate(test_matrix, pred_matrix))