def test_autoregressive_ad_dataframe(): """Make sure deepcopy works """ df = pd.DataFrame( np.array( [ [13, -8, 5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 6, 9, 15, 24], [24, 15, 9, 6, 3, 2, 1, 1, 0, 1, -1, 2, -3, 5, -8, 13], ] ).T, columns=["A", "B"], index=pd.date_range(start="2017-1-1", periods=16, freq="D"), ) a_true = pd.DataFrame( np.array( [ [nan, nan, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [nan, nan, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] ).T, columns=["A", "B"], index=pd.date_range(start="2017-1-1", periods=16, freq="D"), ) model = detector.AutoregressionAD( n_steps=2, side="both", regressor=SVR(kernel="linear") ) for i in range(2): a = model.fit_detect(df.iloc[:, i]) pd.testing.assert_series_equal(a, a_true.iloc[:, i], check_dtype=False) a = model.fit_detect(df) pd.testing.assert_frame_equal(a, a_true, check_dtype=False)
# We have 4 types of models # - one-to-one: input a univariate series, output a univariate series # - one-to-many: input a univariate series, output a multivariate series # - many-to-one: input a multivariate series, output a univariate series # - many-to-many: input a multivariate series, output a multivariate series one2one_models = [ detector.ThresholdAD(), detector.QuantileAD(), detector.InterQuartileRangeAD(), detector.GeneralizedESDTestAD(), detector.PersistAD(), detector.LevelShiftAD(), detector.VolatilityShiftAD(), detector.AutoregressionAD(), detector.SeasonalAD(freq=2), transformer.RollingAggregate(agg="median"), transformer.RollingAggregate(agg="quantile", agg_params={"q": 0.5}), transformer.DoubleRollingAggregate(agg="median"), transformer.DoubleRollingAggregate( agg="quantile", agg_params={"q": [0.1, 0.5, 0.9]} ), transformer.DoubleRollingAggregate( agg="hist", agg_params={"bins": [30, 50, 70]} ), transformer.StandardScale(), transformer.ClassicSeasonalDecomposition(freq=2), ] one2many_models = [