arundo/adtk

Can it save combination of ADs as a model ?

engineeryashsaxena opened this issue · 3 comments

I take a time series and run the following algorithms from ADTK on the series :

  1. Seasonal AD
  2. Persist AD
  3. LevelShift AD

Now I combine the results where if there is any anomaly detected using any of the algorithm I term that instance ( day /hour ) as an anomaly . Now this task needs to be performed everyday , so that I can get the anomalies on the previous day.

Consider the following example :
Let's say today is 14th March 2020
I have a time series from 1st March 2018 at a daily granularity .
Now I run the above algorithms and combine the results till 13th March 2020, I am interested in finding whether there was an anomaly on 13th or not and similarly this will be a task on a daily basis where I will check for 14th Mar , then 15th Mar and so on for each day being an anomaly or not.

My question is can I save the initial thing as a model and have the option of querying the model everyday by giving last days data ( even if I have to give the complete time series that is still okay )
But can I output this as a model ?

Please ask if any clarification is required.

@tailaiw Pls let me know

Yes, you may save your model object by pickling it, something like the following

my_model = MyModel(my_param)
my_model.fit(my_training_data)

with open(my_pickle_path, 'wb') as f:
    pickle.dump(my_model, f)

And when you need to reuse it,

with open(my_pickle_path, 'rb') as f:
    my_model = pickle.load(f)

my_model.detect(my_testing_data)

@tailaiw, when the return type of fit(...) function is None, how do you save/load it by pickling and then run detect(...). Doesn't it return the following error? (I am referring to AutoregressionAD)

'NoneType' object has no attribute 'detect'

P.S. I appreciate that you discuss at this link to some extend, but it is confusing having such function (fit) but not able to use it as "fit and predict" fashion in terms of API design.