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])
获取价值错误:(22,'无效的参数') 在行:t_str = time.strftime('%Y-%m-%d%H:%M%S',time.localtime(timestamp))
使用Python 2.7
谢谢:)
答案 0 :(得分:4)
该示例在添加import time
和定义ts
后有效。使用time.localtime假设您的起始数据使用unix时间。注意到AnomalyDetector的其他参数here。可用的算法定义为here。如果未指定algorithm_name
,则AnomalyDetector会回退到使用加权值default_detector和exponential averages的derivatives。这些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]