#NEWLINE# def mean_subtraction_cumulation( timeseries ) : #NEWLINE# #INDENT# '\n    A timeseries is anomalous if the value of the next datapoint in the\n    series is farther than three standard deviations out in cumulative terms\n    after subtracting the mean from each data point.\n    ' #NEWLINE# series = pandas . Series ( [ ( x [ 1 ] if x [ 1 ] else 0 ) for x in timeseries ] ) #NEWLINE# series = ( series - series [ 0 : ( len ( series ) - 1 ) ] . mean ( ) ) #NEWLINE# stdDev = series [ 0 : ( len ( series ) - 1 ) ] . std ( ) #NEWLINE# expAverage = pandas . stats . moments . ewma ( series , com = 15 ) #NEWLINE# return ( abs ( series . iget ( ( - 1 ) ) ) > ( 3 * stdDev ) )