arundo / adtk

A Python toolkit for rule-based/unsupervised anomaly detection in time series
https://adtk.readthedocs.io
Mozilla Public License 2.0
1.06k stars 143 forks source link

Non binary result for Anomaly detector #118

Open tibhar940 opened 3 years ago

tibhar940 commented 3 years ago

Is there any easy way for returning non-binary result for anomaly detector? For example how to make pipeline for QuantileAD(high=0.99, low=0.01) there results will be presented as {-1,0,1}? I tried this way:


def Waprice(df):
    return df["waprice"]

steps = {
    "waprice_1": {
        "model": CustomizedTransformerHD(transform_func=Waprice),
        "input": "original"
    },
    "waprice_2": {
        "model": CustomizedTransformerHD(transform_func=Waprice),
        "input": "original"
    },
    "waprice_neg": {
        "model": QuantileAd(low=0.01),
        "input": "waprice_1"
    },
    "waprice_pos": {
        "model": QuantileAd(high=0.99),
        "input": "waprice_2"
    },
    "final": {
        "model": # ?,
        "input": # ?
    }
}
pipeline = Pipenet(steps)

But I don't know how I can finalize waprice_neg and waprice_pos. Thank you.

tailaiw commented 3 years ago

I'm not sure I understand your need correctly, but seems you can use a CustomizedTransformer at final to "post-process" the binary output from the two detectors?

tibhar940 commented 3 years ago

I'm not sure I understand your need correctly, but seems you can use a CustomizedTransformer at final to "post-process" the binary output from the two detectors?

@tailaiw Could you please provide an example? My results from detectors: waprice_pos = [0, 1, 1, 0, 0] waprice_neg = [1, 0, 0, 1, 0]

final result should be generated with this logic - "if waprice_pos == 1 then result = 1, if waprice_pos == 0 and waprice_neg == 0 then result = 0, if waprice_neg == 1 then result = -1" result = [-1, 1, 1, -1, 0]