sintel-dev / Orion

A machine learning library for detecting anomalies in signals.
https://sintel.dev/Orion/
MIT License
1.03k stars 160 forks source link

Training model with tadGAN #128

Closed JINU8 closed 3 years ago

JINU8 commented 3 years ago

Description

I am trying to train a model using tadGAN, I am referring to your article on medium https://medium.com/mit-data-to-ai-lab/time-series-anomaly-detection-in-the-era-of-deep-learning-f0237902224a. I using my own data, I have prepossessed data. Iam trying use the fit function, but I couldn't import hyperparameters from model. Is there a workaround ?

What I Did

from model import hyperparameters
from orion.primitives.tadgan import TadGAN

hyperparameters["epochs"] = 100
hyperparameters["shape"] = (100, 1) # based on the window size
hyperparameters["optimizer"] = "keras.optimizers.Adam"
hyperparameters["learning_rate"] = 0.0005
hyperparameters["latent_dim"] = 20
hyperparameters["batch_size"] = 64

tgan = TadGAN(**hyperparameters)
tgan.fit(X)

Is there any package that I missed? I had installed orion-ml using pip.

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-45-29503c3ad6c7> in <module>
----> 1 from model import hyperparameters
      2 from orion.primitives.tadgan import TadGAN

ModuleNotFoundError: No module named 'model'
sarahmish commented 3 years ago

Hi @JINU8, to use your own data that was already preprocessed, you can use the same tadgan pipeline that skips the preprocessing steps that you have already accomplished. For example the tadgan pipeline has the following primitives:

"primitives": [
    "mlprimitives.custom.timeseries_preprocessing.time_segments_aggregate",
    "sklearn.impute.SimpleImputer",
    "sklearn.preprocessing.MinMaxScaler",
    "mlprimitives.custom.timeseries_preprocessing.rolling_window_sequences",
    "orion.primitives.tadgan.TadGAN",
    "orion.primitives.tadgan.score_anomalies",
    "orion.primitives.timeseries_anomalies.find_anomalies"
]

Assuming that your series is already equispaced, imputed and scaled, you can remove the first 3 primitives and their settings in the remainder of the tadgan.json file. The entire file can be found here.

the hyperparameters referred to in your snippet of code is part of the tulog setup that you can find here. I recommend cloning this repo and going through the blogpost and the accompanying notebook together, you can also change the model settings directly from there to fit your data.

sarahmish commented 3 years ago

Closing this issue, the question has been answered.