INNER CODE UNIT · Python
outlier_detect_arbitrary
ashishpatel26/Amazing-Feature-Engineering · feature_cleaning/outlier.py:7
def outlier_detect_arbitrary(data,col,upper_fence,lower_fence):
'''
identify outliers based on arbitrary boundaries passed to the function.
'''
para = (upper_fence, lower_fence)
tmp = pd.concat([data[col]>upper_fence,data[col]<lower_fence],axis=1)
outlier_index = tmp.any(axis=1)
print('Num of outlier detected:',outlier_index.value_counts()[1])
print('Proportion of outlier detected',outlier_index.value_counts()[1]/len(outlier_index))
return outlier_index, para
def outlier_detect_IQR(data,col,threshold=3):
'''
outlier detection by Interquartile Ranges Rule, also known as Tukey's test.
calculate the IQR ( 75th quantile - 25th quantile)