Example #1
0
def test_nonunique_output():
    with pytest.raises(ValueError, match="ambiguous"):
        Pipenet([
            {
                "name": "deseasonal_residual",
                "model": (transformer.NaiveSeasonalDecomposition(freq=6)),
                "input": "original",
            },
            {
                "name": "abs_residual",
                "model":
                transformer.CustomizedTransformer1D(transform_func=abs),
                "input": "deseasonal_residual",
            },
            {
                "name": "iqr_ad",
                "model": detector.InterQuartileRangeAD(c=(None, 3)),
                "input": "abs_residual",
            },
            {
                "name": "sign_check",
                "model": detector.ThresholdAD(high=0.0, low=-float("inf")),
                "input": "deseasonal_residual",
            },
        ])
Example #2
0
def test_pipeline():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )
    my_pipe = Pipeline([
        (
            "deseasonal_residual",
            transformer.NaiveSeasonalDecomposition(freq=6),
        ),
        (
            "abs_residual",
            transformer.CustomizedTransformer1D(transform_func=abs),
        ),
        ("iqr_ad", detector.InterQuartileRangeAD(c=(None, 3))),
    ])

    my_pipe.fit_detect(s)
Example #3
0
def test_transformer_pipe():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )
    my_pipe = Pipenet([
        {
            "name": "deseasonal_residual",
            "model": transformer.NaiveSeasonalDecomposition(freq=6),
            "input": "original",
        },
        {
            "name": "abs_residual",
            "model": transformer.CustomizedTransformer1D(transform_func=abs),
            "input": "deseasonal_residual",
        },
    ])
    with pytest.raises(RuntimeError, match="`fit_transform`"):
        my_pipe.fit_detect(s)
    my_pipe.fit_transform(s)
Example #4
0
def test_detector_return_intermediate():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )
    my_pipe = Pipenet([
        {
            "name": "deseasonal_residual",
            "model": (transformer.NaiveSeasonalDecomposition(freq=6)),
            "input": "original",
        },
        {
            "name": "abs_residual",
            "model": transformer.CustomizedTransformer1D(transform_func=abs),
            "input": "deseasonal_residual",
        },
        {
            "name": "iqr_ad",
            "model": detector.InterQuartileRangeAD(c=(None, 3)),
            "input": "abs_residual",
        },
        {
            "name": "sign_check",
            "model": detector.ThresholdAD(high=0.0, low=-float("inf")),
            "input": "deseasonal_residual",
        },
        {
            "name": "and",
            "model": aggregator.AndAggregator(),
            "input": ["iqr_ad", "sign_check"],
        },
    ])
    result = my_pipe.fit_detect(s, return_intermediate=True)
    assert set(result.keys()) == {
        "original",
        "deseasonal_residual",
        "abs_residual",
        "iqr_ad",
        "sign_check",
        "and",
    }
Example #5
0
def test_skip_fit():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )

    deseasonal_residual = transformer.NaiveSeasonalDecomposition(freq=6)

    my_pipe = Pipenet([
        {
            "name": "deseasonal_residual",
            "model": deseasonal_residual,
            "input": "original",
        },
        {
            "name": "abs_residual",
            "model": transformer.CustomizedTransformer1D(transform_func=abs),
            "input": "deseasonal_residual",
        },
        {
            "name": "iqr_ad",
            "model": detector.InterQuartileRangeAD(c=(None, 3)),
            "input": "abs_residual",
        },
        {
            "name": "sign_check",
            "model": detector.ThresholdAD(high=0.0, low=-float("inf")),
            "input": "deseasonal_residual",
        },
        {
            "name": "and",
            "model": aggregator.AndAggregator(),
            "input": ["iqr_ad", "sign_check"],
        },
    ])
    with pytest.raises(RuntimeError):
        my_pipe.fit_detect(s, skip_fit=["deseasonal_residual"])
    my_pipe.fit_detect(s)
Example #6
0
    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.NaiveSeasonalDecomposition(freq=2),
    transformer.STLDecomposition(freq=2),
]

one2many_models = [
    transformer.RollingAggregate(agg="quantile",
                                 agg_params={"q": [0.1, 0.5, 0.9]}),
    transformer.RollingAggregate(agg="hist", agg_params={"bins": [20, 50,
                                                                  80]}),
    transformer.Retrospect(n_steps=3),
]

many2one_models = [
    detector.MinClusterDetector(KMeans(n_clusters=2)),
    detector.OutlierDetector(
        LocalOutlierFactor(n_neighbors=20, contamination=0.1)),