Linkedin Luminol 异常检测和关联库的工作示例

Working Example Of Luminol Anomaly Detection And Correlation Library By Linkedin

Github Link 鲁米诺图书馆:https://github.com/linkedin/luminol

任何人都可以用示例代码向我解释如何使用此模块查找数据集中的异常情况。

我想使用这个模块来查找我的时间序列数据中的异常。

P.S.: 我尝试了 README.md 中提供的示例 1,但出现错误,所以有人请给我提供一个用于查找异常的工作示例。

示例 1 将异常分数放入列表中。

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])

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

使用 Python 2.7

谢谢:)

该示例在添加 import time 并定义 ts 后运行。使用 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 也可能有帮助。

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)

输出:

['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]