-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_preprocessing_timeseries.py
More file actions
47 lines (41 loc) · 1.57 KB
/
test_preprocessing_timeseries.py
File metadata and controls
47 lines (41 loc) · 1.57 KB
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
"""
@brief test log(time=2s)
"""
import unittest
import numpy
from pyquickhelper.pycode import ExtTestCase
from mlinsights.timeseries import build_ts_X_y
from mlinsights.timeseries.base import BaseTimeSeries
from mlinsights.timeseries.preprocessing import TimeSeriesDifference
class TestPreprocessingTimeSeries(ExtTestCase):
def test_base_parameters_split0(self):
X = numpy.arange(20).reshape((10, 2))
y = numpy.arange(10) * 100
bs = BaseTimeSeries(past=2)
nx, ny, _ = build_ts_X_y(bs, X, y)
for d in range(0, 5):
proc = TimeSeriesDifference(d)
proc.fit(nx, ny)
px, py = proc.transform(nx, ny)
self.assertEqualArray(px[-1, :], nx[-1, :])
rev = proc.get_fct_inv()
ppx, ppy = rev.transform(px, py)
self.assertEqualArray(nx, ppx)
self.assertEqualArray(ny, ppy)
def test_base_parameters_split0_weight(self):
X = numpy.arange(20).reshape((10, 2))
y = numpy.arange(10) * 100
bs = BaseTimeSeries(past=2)
nx, ny, _ = build_ts_X_y(bs, X, y)
weights = numpy.ones((nx.shape[0], ), dtype=nx.dtype)
for d in range(0, 5):
proc = TimeSeriesDifference(d)
proc.fit(nx, ny, weights)
px, py = proc.transform(nx, ny)
self.assertEqualArray(px[-1, :], nx[-1, :])
rev = proc.get_fct_inv()
ppx, ppy = rev.transform(px, py)
self.assertEqualArray(nx, ppx)
self.assertEqualArray(ny, ppy)
if __name__ == "__main__":
unittest.main()