Simplify time series forecasting


Keywords
Time, series, forecasting, anomaly, detection
License
MIT
Install
pip install gtsfutur==0.1.6.7.5

Documentation

General Time Serie Prediction and Anomalies Detection

PyPI version
Exemple of LSTM + DECOMPOSITION prédiction :

LSTM PRED

Full documentation available here : https://gtsfutur.readthedocs.io/en/latest/index.html .

Summary

-GSFutur object
-Use case prediction
-Results prediction
-Use case anomalies detection
-Results anomalies detection

GTSPredictor object

This object simplify prediction by hidding all the paramaters for the user. Let's focus on the most important methods :
-fit()
-predict()
-retrain()
-prediction_eval()
-load_models()

Install

pip install GTSFutur

Use prediction

Example use case (The dataframe needs to have a columns named "time" and one named "y" in order to work)
my dataframe (df) is like below and have a 200 points seasonal pattern :
"time","y"
"1749-01",58.0
"1749-02",62.6
"1749-03",70.0
...
Code for prediction 365 steps ahead

from GTSFutur.GTSPredictor import GTSPredictor
model=GTSPredictor()
model.fit(df,look_back=400,freq_period=200,directory="My_directory_name")
prediction,lower,upper=model.predict(steps=365)

Code for prediction 365 steps ahead using the user interface

from GTSFutur.GTSPredictor import GTSPredictor
model=GTSPredictor()
model.fit_with_UI(df,directory="My_directory_name")
prediction,lower,upper=model.predict(steps=365)

This will open a matplotlib figure and you will be able to select the seasonal pattern with the mouse

plot

model.plot_prediction(df,prediction,lower,upper)

reuse a saved model

model=model.reuse(df,directory="My_directory_name")

Retrain the model (on new data for example in order to do incremental learning)

# before the model need to be loaded either it's just after the first training or used reuse function
model=model.retrain(df)

Results prediction

LSTM PRED Theses are "out of the box" results. The only parameter to determine was the size of the seasonal pattern which is easy to find as he can be determine through visual inspection

Use anomalies detection

Detect disruption in the seasonal shape for contextual anomalies:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=Period_Detector()
    detector.fit(data)
    anomaly=detector.detect(data,threshold=0.2)
    detector.plot_anomalies(anomaly,data)

Detect points far from the average statical distribution:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=IEQ_Detector()
    detector.fit(data)
    #alpha a severity parameter
    anomaly=detector.detect(data,alpha=1.96)
    detector.plot_anomalies(anomaly,data)

Detect points far from the median:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=Mad_Detector()
    detector.fit(data)
    anomaly=detector.detect(data,alpha=0.6785)
    detector.plot_anomalies(anomaly,data)

Detect important changes of values for measurements like mean,standard deviation and median on slidding windows:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=Variation_Detector(method="std")
    detector.fit(data)
    anomaly=detector.detect(data,threshold=0.5,windows_size=25)
    detector.plot_anomalies(anomaly,data)

Detect peaks once the signal denoised with wavelet decomposition:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=Wave_Detector()
    detector.fit(data,threshold=0.3)
    anomaly=detector.detect(data,alpha=10)
    detector.plot_anomalies(anomaly,data)

Use a LSTM auto encoder to detect more complexe, global and contextual, anomalies:

    from GTSFutur.GTSDetector import Wave_Detector,Period_Detector,Mad_Detector,Variation_Detector,Autoencoder_Detector,IEQ_Detector
    detector=Autoencoder_Detector()
    detector.fit(100,data,"My_directory_name")
    anomaly=detector.detect(data,"My_directory_name",threshold=5)
    detector.plot_anomalies(anomaly,data)

Results anomalies detection

Anomaly