-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_zaggy.py
48 lines (40 loc) · 1.56 KB
/
test_zaggy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import unittest
from unittest import TestCase
from mocks import make_mock
from seasonality import get_seasonality_matrix
from date_scaling import date_range
from zaggy import l1_fit
import numpy as np
class TestZaggy(TestCase):
"""
Test the zaggy time series fitting with some seasonality
"""
def setUp(self):
self.mock = make_mock(do_plot=False)
self.y = self.mock['y']
self.num = len(self.y)
self.dates = date_range(2015, 1, 2029, 12)[0:self.num]
self.assertEquals(len(self.y), len(self.dates))
seas_func = lambda date: date.month-1
self.seasonality_matrix, self.compression_dict = \
get_seasonality_matrix(self.dates, seasonality_function=seas_func)
def test_l1_fit_runs(self):
index = np.arange(self.num)
result = l1_fit(index, self.y,
seasonality_matrix=self.seasonality_matrix)
self.assertEquals(len(result['model']), self.num)
def test_l1_fit_runs_correctly(self):
# how low can we shrink this tolerance and still pass?
tol = 0.03
index = np.arange(self.num)
result = l1_fit(index, self.y,
seasonality_matrix=self.seasonality_matrix)
model = result['model']
self.assertEquals(len(model), self.num)
for x_value, y_value, model_value in zip(index, self.y, model):
diff = model_value - y_value
print x_value, y_value, model_value, diff
self.assertLess(abs(diff), tol)
assert True
if __name__ == "__main__":
unittest.main()