MAD 定义为,一元序列 Xi 同其中位数偏差的绝对值的中位数(deviation,偏差本身有正有负);

|)

1. MAD 用于异常点的检测

假定数据服从正态分布,我们让异常点(outliers)落在两侧的 50% 的面积里,让正常值落在中间的 50% 的区域里:

/2

其中 /σ=0.6749。

from scipy.stats import norm

def mad_based_outlier(points, thresh=3.5):
    if type(points) is list:
        points = np.asarray(points)
    if len(points.shape) == 1:
        points = points[:, None]
    med = np.median(points, axis=0)
    abs_dev = np.absolute(points - med)
    med_abs_dev = np.median(abs_dev)

    mod_z_score = norm.ppf(0.75) * abs_dev / med_abs_dev
    return mod_z_score > thresh

2. MAD 与基于分位数方法的对比

MAD 的方法相对于分位数方法的一大优势即在于 MAD 方法对样本大小是不敏感也即是稳定的鲁棒的一种评价指标。

def percentile_based_outlier(data, threshold=95):
    diff = (100 - threshold) / 2.0
    minval, maxval = np.percentile(data, [diff, 100 - diff])
    return (data < minval) | (data > maxval)

Pythonic way of detecting outliers in one dimensional observation data

相关文章:

  • 2022-01-12
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-09-26
  • 2022-01-02
  • 2022-12-23
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-12-18
  • 2021-06-03
  • 2021-07-23
  • 2021-04-13
相关资源
相似解决方案