def test_estimator_reduce_l2(self): real_weights = [0.66470588, 0.33529412] conv = CSVDataConverter(TEST_WEATHER_PATH) est = StandardEstimator(*conv.convert(KEY_MAP)) est.reduce() for d, r in zip(est.weights['temperature'].T[0], real_weights): self.assertAlmostEqual(d, r)
def test_to_list(self): conv = CSVDataConverter(TEST_WEATHER_PATH) est = StandardEstimator(*conv.convert(KEY_MAP)) est.reduce() data = to_list(est.produce(conv.predict)['data']) for v in data.values(): self.assertTrue(isinstance(v, list))
def test_estimator_reduce_l1(self): real_weights = [0.57777778, 0.42222222] conv = CSVDataConverter(TEST_WEATHER_PATH) est = StandardEstimator(*conv.convert(KEY_MAP)) est.reduce(MinkowskiReducer()) for d, r in zip(est.weights['temperature'].T[0], real_weights): self.assertAlmostEqual(d, r)
class TestTestDataConverter(unittest.TestCase): def setUp(self): self.conv = CSVDataConverter(TEST_WEATHER_PATH) def test_convert(self): predict, real = self.conv.convert(KEY_MAP) self.assertEqual(predict['data']['temperature'].shape, (2, 20)) self.assertEqual(real['data']['temperature'].shape, (1, 20)) def test_service_names(self): services = {'gismeteo': 1, 'meteoprog': 1} self.assertListEqual(list(services.keys()), self.conv.service_names().tolist())
def test_from_converter(self): real_weights = [0.57777778, 0.42222222] est = StandardEstimator.from_converter( CSVDataConverter(TEST_WEATHER_PATH), KEY_MAP) est.reduce(MinkowskiReducer()) for d, r in zip(est.weights['temperature'].T[0], real_weights): self.assertAlmostEqual(d, r)
def test_estimator_produce(self): test_temp_list = numpy.array([-3, 7, -4, 6]).reshape(2, 2) data = { 'data': { 'temperature': test_temp_list, }, 'slots': ['one', 'two'], 'labels': [i for i in range(test_temp_list.shape[1])] } conv = CSVDataConverter(TEST_WEATHER_PATH) est = StandardEstimator(*conv.convert(KEY_MAP)) est.reduce(EuclideanReducer()) w = est.weights['temperature'] res = est.produce(data)['data']['temperature'] test_res = w.T.dot(test_temp_list) self.assertEqual(test_res[0, 0], res[0, 0]) self.assertEqual(test_res[0, 1], res[0, 1])
def test_estimator_type_error_raise(self): conv = CSVDataConverter(TEST_WEATHER_PATH) pred, real = conv.convert(KEY_MAP) del pred['slots'] with self.assertRaises(KeyError): StandardEstimator(pred, real)
def setUp(self): self.conv = CSVDataConverter(TEST_WEATHER_PATH)