Finding outliers in forecasts

Suppose I have a list of forecasts like 0,0,0,0,0,100,0,0 and I want to find the outlier (100 in this case).  For the record, I will call an outlier anything which is greater than 1 standard deviation from the median, as follows:


import numpy as np

def get_outliers(L):
  median = np.median(L)
  sdev = np.std(L)
  O = set([x for x in L if abs(x-median) > sdev])
  return list(O)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s