我刚刚开始进行时间序列预测,并试图为后续用例找出解决方案。 我想检测到非季节性警报进入我们的系统。如果传入警报是季节性的,我想忽略它们。不适合季节性模式的异常值,我需要将其升级到处理模块。
#Creating time series which has spikes every 20th time interval.
alert_once_a_day = [1.0 if i % 20 == 0 else 0.0 for i in range(100)]
#Adding an outlier at 27, which does not fit pattern of spikes at every 20 th interval.
alert_once_a_day[27] =1.0
在以上系列中,我想查找所有警报以季节性模式出现并忽略它们。
答案 0 :(得分:0)
最简单的答案,请使用遮罩:
alert_once_a_day = [1.0 if i % 20 == 0 else 0.0 for i in range(100)]
seasonal_alerts = list(alert_once_a_day)
mask = np.array(seasonal_alerts) == 0
#Adding an outlier at 27, which does not fit pattern of spikes at every 20 th interval.
alert_once_a_day[27] =1.0
# assuming your zeros are "non alert" values, the mask will eliminate seasonal peaks:
true_alerts = np.where(np.array(alert_once_a_day) * mask==1)
true_alerts
>> (array([27], dtype=int64),)