Linkedin 的 Luminol 异常检测和相关库的工作示例
Posted
技术标签:
【中文标题】Linkedin 的 Luminol 异常检测和相关库的工作示例【英文标题】:Working Example Of Luminol Anomaly Detection And Correlation Library By Linkedin 【发布时间】:2017-06-23 10:13:04 【问题描述】:Luminol 库的 Github 链接: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
谢谢:)
【问题讨论】:
【参考方案1】:该示例在添加import time
并定义ts
后有效。 time.localtime 的使用假定您的起始数据使用 unix 时间。 AnomalyDetector 的其他参数在here 中注明。可用算法定义为here。如果未指定 algorithm_name
,则 AnomalyDetector 会回退到使用 default_detector,它使用 exponential averages 和 derivatives 的加权和。这些slides 也可能会有所帮助。
数据.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]
【讨论】:
以上是关于Linkedin 的 Luminol 异常检测和相关库的工作示例的主要内容,如果未能解决你的问题,请参考以下文章