Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2015 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/fe9a13c61f29baabd766 to your computer and use it in GitHub Desktop.
Save anonymous/fe9a13c61f29baabd766 to your computer and use it in GitHub Desktop.
def mad_based_outlier(points, thresh=3.5):
if len(points.shape) == 1:
points = points[:,None]
median = np.median(points, axis=0)
diff = np.sum((points - median)**2, axis=-1)
diff = np.sqrt(diff)
med_abs_deviation = np.median(diff)
modified_z_score = 0.6745 * diff / med_abs_deviation
return modified_z_score > thresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment