Home

Awesome

Downloads Downloads License: MIT PWC

About arimafd

Arimafd is a Python package that provides algorithms for online prediction and anomaly detection. One of the applications of this package can be the early detection of faults in technical systems.

Main Features

How to get it

Get started

Example #1

import pandas as pd
import numpy as np
import arimafd as oa

my_array = np.random.normal(size=1000) # init array
my_array[-3] = 1000 # init anomaly
ts = pd.DataFrame(my_array,
                  index=pd.date_range(start='01-01-2000',
                                      periods=1000,
                                      freq='H'))

my_arima = oa.Arima_anomaly_detection(ar_order=3)
my_arima.fit(ts[:500])
ts_anomaly = my_arima.predict(ts[500:])


# or you can use for streaming:
# bin_metric = []
# for i in range(len(df)):
#     bin_metric.append(my_arima.predict(df[i:i+1]))
# bin_metric = pd.concat(bin_metric)
# bin_metric
ts_anomaly

[Output]:

2000-01-21 20:00:00    0
2000-01-21 21:00:00    0
2000-01-21 22:00:00    0
2000-01-21 23:00:00    0
2000-01-22 00:00:00    0
                      ..
2000-02-11 11:00:00    0
2000-02-11 12:00:00    0
2000-02-11 13:00:00    0
2000-02-11 14:00:00    1
2000-02-11 15:00:00    1
Freq: H, Length: 997, dtype: int32

Actually, labeling time series on anomaly and not an anomaly have already been performed by proc_tensor function (it returns labeled time series, where 1 is an anomaly, 0 - not anomaly).

For evaluating results you can use https://tsad.readthedocs.io/en/latest/Evaluating.html

Example #2

import pandas as pd
import numpy as np
import arimafd as oa

my_array = np.random.normal(size=1000) # init array
my_array[-3] = 1000 # init anomaly
ts = pd.DataFrame(my_array,
                  index=pd.date_range(start='01-01-2000',
                                      periods=1000,
                                      freq='H'))
ad = oa.Anomaly_detection(ts) #init anomaly detection algorithm
ad.generate_tensor(ar_order=3) #it compute weights of ARIMA on history 
ts_anomaly = ad.proc_tensor() #processing of weights. 
ts_anomaly

License

MIT