Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working Example Of Luminol Anomaly Detection And Correlation Library By Linkedin

Github Link Of Luminol Library: https://github.com/linkedin/luminol

Can anyone explain me with a sample code, how to use this module for finding anomalies in data set.

I want to use this module for finding the anomalies in my time series data.

P.S.: I tried the example 1 provided in README.md but getting error, so someone please provide me a working example for finding anomalies.

Example 1 Put anomaly scores in a list.

from luminol.anomaly_detector import AnomalyDetector
my_detector = AnomalyDetector(ts)
score = my_detector.get_all_scores()
anom_score = list()
for (timestamp, value) in score.iteritems():
    t_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
    anom_score.append([t_str, value])

Getting value error: (22, 'Invalid argument') In line: t_str = time.strftime('%Y-%m-%d %H :%M%S', time.localtime(timestamp))

Using Python 2.7

Thanks :)

like image 878
Ashish Avatar asked Feb 06 '17 12:02

Ashish


People also ask

What are the examples of anomaly detection?

Catching and identifying anomalies is what we call anomaly or outlier detection. For example, if large sums of money are spent one after another within one day and it is not your typical behavior, a bank can block your card. They will see an unusual pattern in your daily transactions.

How do you set up Anomaly Detection?

Enable Anomaly Detection During that time, the machine learning models train on the business transactions in your application. Select Alert & Respond > Anomaly Detection > Model Training to view Business Transaction training status.

How do you detect anomalies in time series?

The procedure for detecting anomalies with ARIMA is: Predict the new point from past datums and find the difference in magnitude with those in the training data. Choose a threshold and identify anomalies based on that difference threshold. That's it!


1 Answers

The example works after adding import time and defining ts. The use of time.localtime presumes your starting data uses unix time. Additional parameters for AnomalyDetector are noted here. The available algorithms are defined here. If algorithm_name is not specified, AnomalyDetector falls back to using the the default_detector which uses a weighted sum of exponential averages and derivatives. These slides might also be helpful.

data.csv

1490323038, 3
1490323048, 4
1490323058, 6
1490323068, 78
1490323078, 67
1490323088, 5

app.py

from luminol.anomaly_detector import AnomalyDetector
import time

# ts = 'data.csv'  # or
ts = { 
    '1490323038': 3,
    '1490323048': 4,
    '1490323058': 6,
    '1490323068': 78,
    '1490323078': 67,
    '1490323088': 5,
}

my_detector = AnomalyDetector(ts)
score = my_detector.get_all_scores()
anom_score = []

for (timestamp, value) in score.iteritems():
    t_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
    anom_score.append([t_str, value])

for score in anom_score:
    print(score)

Output:

['2017-03-23 19:37:18', 0.0]
['2017-03-23 19:37:28', 0.02482518793211144]
['2017-03-23 19:37:38', 0.06951052620991202]
['2017-03-23 19:37:48', 2.5187085350547482]
['2017-03-23 19:37:58', 1.201340494410737]
['2017-03-23 19:38:08', 0.9673414624904575]
like image 50
brennan Avatar answered Oct 27 '22 00:10

brennan