Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
add 2 sample Kolmogorov-Smirnov test
Browse files Browse the repository at this point in the history
  • Loading branch information
mabrek committed Aug 14, 2013
1 parent f7b6163 commit f886000
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/analyzer/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ def histogram_bins(timeseries):

return False

def ks_test(timeseries):
"""
A timeseries is anomalous if 2 sample Kolmogorov-Smirnov test indicates
that data distribution for last 10 minutes is different from last hour.
It produces false positives on non-stationary series so Augmented
Dickey–Fuller test applied to check for stationarity.
"""

hour_ago = time() - 3600
ten_minutes_ago = time() - 600
reference = scipy.array([x[1] for x in timeseries if x[0] >= hour_ago and x[0] < ten_minutes_ago])
probe = scipy.array([x[1] for x in timeseries if x[0] >= ten_minutes_ago])
ks_d,ks_p_value = scipy.stats.ks_2samp(reference, probe)

if ks_p_value < 0.05 and ks_d > 0.5:
adf = sm.tsa.stattools.adfuller(reference, 10)
if adf[1] < 0.05:
return True

return False

def run_selected_algorithm(timeseries):
"""
Expand Down

0 comments on commit f886000

Please sign in to comment.