Twitter异常检测框架BreakoutDetection Python版

前言

在Github上最火的异常检测算法就是Twitter的BreakoutDetection了 https://github.com/twitter/AnomalyDetection
关于它的介绍 https://blog.twitter.com/engineering/en_us/a/2015/introducing-practical-and-robust-anomaly-detection-in-a-time-series.html
在这里插入图片描述
但是只是R语言的。

然而有好多人把它用python实现了一遍:

  1. https://github.com/roland-hochmuth/BreakoutDetection
  2. https://github.com/indeedeng/anomaly-detection
  3. https://pypi.org/project/pyculiarity/

我试了一下,最友好的就是 https://pypi.org/project/pyculiarity/ 这个了。

安装

pip install pyculiarity

在安装的时候报错:

ImportError: cannot import name 'TimeSeries'

再继续执行以下更新就好了

pip install statsmodels --upgrade

运行

from pyculiarity import detect_ts
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd

# raw_data.csv 数据在这里 https://github.com/zrnsm/pyculiarity/blob/master/tests/raw_data.csv 
t = pd.read_csv('raw_data.csv', usecols=['timestamp', 'count'])
df = pd.read_csv('raw_data.csv', usecols=['timestamp', 'count'])
results = detect_ts(t,max_anoms=0.007,direction='both')

df.time = pd.to_datetime(df.timestamp)
df.time2 = pd.to_datetime(results['anoms']['timestamp'])
print(df.time2)
plt.plot(df.time,df['count'])
plt.plot(df.time2,results['anoms']['anoms'], 'ro')
plt.grid(True)
plt.show()

结果:红色的是异常点
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值