Skip to content

Instantly share code, notes, and snippets.

@letthedataconfess
Created February 1, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letthedataconfess/6f2645fc156842b972fb948b9c0dc195 to your computer and use it in GitHub Desktop.
Save letthedataconfess/6f2645fc156842b972fb948b9c0dc195 to your computer and use it in GitHub Desktop.
outlier detection
import numpy as np
outliers=[]
dataset=[11,10,12,14,12,15,14,13,15,102,12,14,17,19,107,10,13,12,14,12,108,12,11,14,13,15,10,15,12,10,14,13,15,10]
def detect_outliers(data):
threshold=3
mean=np.mean(data)
std=np.std(data)
for i in dataset:
z_score=(i-mean)/std
if np.abs(z_score)>threshold:
outliers.append(i)
return outliers;
outlier_pt=detect_outliers(dataset)
print(outliers_pt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment