Skip to content

Commit

Permalink
Merge pull request #310 from lscheinkman/RES-561
Browse files Browse the repository at this point in the history
RES-561: Fix pandas deprecation warnings.
  • Loading branch information
lscheinkman authored Aug 16, 2017
2 parents 9206065 + a333c76 commit 4e45930
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, *args, **kwargs):
self.util = []

# Number of bins into which util is to be quantized
self.N_bins = 5.0
self.N_bins = 5

# Window size
self.W = 52
Expand Down
25 changes: 15 additions & 10 deletions nab/detectors/skyline/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
the best combination of algorithms for NAB is included below.
"""

import pandas
import numpy as np
from datetime import datetime, timedelta

import numpy as np
import pandas



def tail_avg(timeseries):
Expand All @@ -23,6 +24,7 @@ def tail_avg(timeseries):
return timeseries[-1][1]



def median_absolute_deviation(timeseries):
"""
A timeseries is anomalous if the deviation of its latest datapoint with
Expand All @@ -34,13 +36,12 @@ def median_absolute_deviation(timeseries):
demedianed = np.abs(series - median)
median_deviation = demedianed.median()


# The test statistic is infinite when the median is zero,
# so it becomes super sensitive. We play it safe and skip when this happens.
if median_deviation == 0:
return False

test_statistic = demedianed.iget(-1) / median_deviation
test_statistic = demedianed.iloc[-1] / median_deviation

# Completely arbitary...triggers if the median deviation is
# 6 times bigger than the median
Expand All @@ -50,6 +51,7 @@ def median_absolute_deviation(timeseries):
return False



# The method below is excluded because it is computationally inefficient
# def grubbs(timeseries):
# """
Expand Down Expand Up @@ -91,6 +93,7 @@ def first_hour_average(timeseries):
return abs(t - mean) > 3 * stdDev



def stddev_from_average(timeseries):
"""
A timeseries is anomalous if the absolute value of the average of the latest
Expand All @@ -106,6 +109,7 @@ def stddev_from_average(timeseries):
return abs(t - mean) > 3 * stdDev



def stddev_from_moving_average(timeseries):
"""
A timeseries is anomalous if the absolute value of the average of the latest
Expand All @@ -114,10 +118,11 @@ def stddev_from_moving_average(timeseries):
respect to the short term trends.
"""
series = pandas.Series([x[1] for x in timeseries])
expAverage = pandas.stats.moments.ewma(series, com=50)
stdDev = pandas.stats.moments.ewmstd(series, com=50)
expAverage = series.ewm(ignore_na=False, min_periods=0, adjust=True, com=50).mean()
stdDev = series.ewm(ignore_na=False, min_periods=0, adjust=True, com=50).std(bias=False)

return abs(series.iloc[-1] - expAverage.iloc[-1]) > 3 * stdDev.iloc[-1]

return abs(series.iget(-1) - expAverage.iget(-1)) > 3 * stdDev.iget(-1)


def mean_subtraction_cumulation(timeseries):
Expand All @@ -130,9 +135,9 @@ def mean_subtraction_cumulation(timeseries):
series = pandas.Series([x[1] if x[1] else 0 for x in timeseries])
series = series - series[0:len(series) - 1].mean()
stdDev = series[0:len(series) - 1].std()
expAverage = pandas.stats.moments.ewma(series, com=15)

return abs(series.iget(-1)) > 3 * stdDev
return abs(series.iloc[-1]) > 3 * stdDev



def least_squares(timeseries):
Expand All @@ -142,7 +147,7 @@ def least_squares(timeseries):
"""

x = np.array(
[(t[0] - datetime(1970,1,1)).total_seconds() for t in timeseries])
[(t[0] - datetime(1970, 1, 1)).total_seconds() for t in timeseries])
y = np.array([t[1] for t in timeseries])
A = np.vstack([x, np.ones(len(x))]).T
results = np.linalg.lstsq(A, y)
Expand Down

0 comments on commit 4e45930

Please sign in to comment.