def test_segmentxyforecast(): Nt = 100 width = 5 nvars = 5 # lets do a forecast test seg = transform.SegmentXYForecast(width=width, forecast=5) Xt = [ np.random.rand(Nt, nvars), np.random.rand(2 * Nt, nvars), np.random.rand(Nt, nvars) ] Xc = np.random.rand(3, 4) y = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 4) # univariate X nvars = 1 seg = transform.SegmentXYForecast(width=width, forecast=5) X = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] y = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width)
def test_segmentxyforecast(): # test illegal parameter settings with pytest.raises(ValueError): transform.SegmentXYForecast(width=0) # illegal width value with pytest.raises(ValueError): transform.SegmentXYForecast( overlap=None, step=None) # either overlap or step must be defined with pytest.raises(ValueError): transform.SegmentXYForecast(overlap=-1, step=None) # illegal overlap value with pytest.raises(ValueError): transform.SegmentXYForecast(step=0) # illegal step value with pytest.raises(ValueError): transform.SegmentXYForecast(order=None) # illegal order with pytest.raises(ValueError): transform.SegmentXYForecast(forecast=0) # illegal forecast value # test _step property working as expected seg = transform.SegmentXYForecast(width=10, overlap=0.5) assert seg._step == 5 # test precedence of step over overlap seg = transform.SegmentXYForecast(width=10, overlap=1, step=1) assert seg._step == 1 # illegal overlap value, but valid step value seg = transform.SegmentXYForecast(overlap=-1, step=1) assert seg._step == 1 # test shape of segmented data Nt = 100 width = 5 nvars = 5 # lets do a forecast test seg = transform.SegmentXYForecast(width=width, forecast=5) Xt = [ np.random.rand(Nt, nvars), np.random.rand(2 * Nt, nvars), np.random.rand(Nt, nvars) ] Xc = np.random.rand(3, 4) y = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] X = TS_Data(Xt, Xc) seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width, nvars) assert Xsc.shape == (N, 4) # univariate X nvars = 1 seg = transform.SegmentXYForecast(width=width, forecast=5) X = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] y = [np.random.rand(Nt), np.random.rand(2 * Nt), np.random.rand(Nt)] seg.fit(X, y) Xs, ys, _ = seg.transform(X, y) Xst, Xsc = get_ts_data_parts(Xs) N = len(ys) assert Xst.shape == (N, width)