Is there a numpy builtin to do something like the following? That is, take a list d
and return a list filtered_d
with any outlying elements removed
Building on Benjamin's, using pandas.Series
, and replacing MAD with IQR:
def reject_outliers(sr, iq_range=0.5):
pcnt = (1 - iq_range) / 2
qlow, median, qhigh = sr.dropna().quantile([pcnt, 0.50, 1-pcnt])
iqr = qhigh - qlow
return sr[ (sr - median).abs() <= iqr]
For instance, if you set iq_range=0.6
, the percentiles of the interquartile-range would become: 0.20 <--> 0.80
, so more outliers will be included.