Online

Online window operations
np.random.seed(0)
y = np.random.rand(100)
def test_online(OnlineOp, regular_op, y, n_updates=10, **op_kwargs):
    expected = regular_op(y, **op_kwargs)
    online = OnlineOp(**op_kwargs)
    calculated = online.fit_transform(y[:-n_updates]).tolist()
    for i in range(y.size - n_updates, y.size):
        calculated.append(online.update(y[i]))
    np.testing.assert_allclose(calculated, expected)

Rolling

Regular


source

RollingMean

 RollingMean (window_size:int, min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(RollingMean, rolling_mean, y, window_size=4, min_samples=1)
test_online(RollingMean, rolling_mean, y, n_updates=90, window_size=14, min_samples=3)
test_online(RollingMean, rolling_mean, y, n_updates=96, window_size=7, min_samples=7)

source

RollingMax

 RollingMax (window_size:int, min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(RollingMax, rolling_max, y, window_size=4, min_samples=1)
test_online(RollingMax, rolling_max, y, n_updates=90, window_size=14, min_samples=3)
test_online(RollingMax, rolling_max, y, n_updates=96, window_size=7, min_samples=7)

source

RollingMin

 RollingMin (window_size:int, min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(RollingMin, rolling_min, y, window_size=4, min_samples=1)
test_online(RollingMin, rolling_min, y, n_updates=90, window_size=14, min_samples=3)
test_online(RollingMin, rolling_min, y, n_updates=96, window_size=7, min_samples=7)

source

RollingStd

 RollingStd (window_size:int, min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(RollingStd, rolling_std, y, window_size=4, min_samples=2)
test_online(RollingStd, rolling_std, y, n_updates=90, window_size=14, min_samples=3)
test_online(RollingStd, rolling_std, y, n_updates=96, window_size=7, min_samples=7)
online_std = RollingStd(7)
online_std.fit_transform(y)
for _ in range(14):
    online_std.update(0)

Seasonal


source

SeasonalRollingMean

 SeasonalRollingMean (season_length:int, window_size:int,
                      min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalRollingMean, seasonal_rolling_mean, y, window_size=4, min_samples=1, season_length=7)
test_online(SeasonalRollingMean, seasonal_rolling_mean, y, n_updates=79, window_size=4, min_samples=2, season_length=7)

source

SeasonalRollingStd

 SeasonalRollingStd (season_length:int, window_size:int,
                     min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalRollingStd, seasonal_rolling_std, y, window_size=4, min_samples=2, season_length=7)
test_online(SeasonalRollingStd, seasonal_rolling_std, y, n_updates=79, window_size=4, min_samples=2, season_length=7)

source

SeasonalRollingMin

 SeasonalRollingMin (season_length:int, window_size:int,
                     min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalRollingMin, seasonal_rolling_min, y, window_size=4, min_samples=1, season_length=7)
test_online(SeasonalRollingMin, seasonal_rolling_min, y, n_updates=79, window_size=4, min_samples=2, season_length=7)

source

SeasonalRollingMax

 SeasonalRollingMax (season_length:int, window_size:int,
                     min_samples:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalRollingMax, seasonal_rolling_max, y, window_size=4, min_samples=1, season_length=7)
test_online(SeasonalRollingMax, seasonal_rolling_max, y, n_updates=79, window_size=4, min_samples=2, season_length=7)

Expanding

Regular


source

ExpandingMean

 ExpandingMean ()

Initialize self. See help(type(self)) for accurate signature.

np.random.seed(0)
y = np.random.rand(100)
test_online(ExpandingMean, expanding_mean, y)

source

ExpandingMax

 ExpandingMax ()

Initialize self. See help(type(self)) for accurate signature.

test_online(ExpandingMax, expanding_max, y)

source

ExpandingMin

 ExpandingMin ()

Initialize self. See help(type(self)) for accurate signature.

test_online(ExpandingMin, expanding_min, y)

source

ExpandingStd

 ExpandingStd ()

Initialize self. See help(type(self)) for accurate signature.

test_online(ExpandingStd, expanding_std, y)

Seasonal


source

SeasonalExpandingMean

 SeasonalExpandingMean (season_length:int)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalExpandingMean, seasonal_expanding_mean, y, season_length=7)

source

SeasonalExpandingStd

 SeasonalExpandingStd (season_length:int)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalExpandingStd, seasonal_expanding_std, y, season_length=7)

source

SeasonalExpandingMin

 SeasonalExpandingMin (season_length:int)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalExpandingMin, seasonal_expanding_min, y, season_length=7)

source

SeasonalExpandingMax

 SeasonalExpandingMax (season_length:int)

Initialize self. See help(type(self)) for accurate signature.

test_online(SeasonalExpandingMax, seasonal_expanding_max, y, season_length=7)

EWM


source

EWMMean

 EWMMean (alpha)

Initialize self. See help(type(self)) for accurate signature.

test_online(EWMMean, ewm_mean, y, alpha=0.3)

Shifting


source

Shift

 Shift (offset:int)

Initialize self. See help(type(self)) for accurate signature.

for offset in (1, 3, 7):
    test_online(Shift, shift_array, y, offset=offset, n_updates=2*offset)