【问题标题】:Determine list indices of Outliers in python在python中确定异常值的列表索引
【发布时间】:2021-02-05 17:13:00
【问题描述】:

我发现它可能在数组上使用numpywhere 条件语句来接收它们的索引,我知道在箱形图中(例如matplotlib.pyplot.subplots().boxplot(...,showfliers=False,...))我将传单的定义解释为“异常值”以 1./3 的形式给出。四分位数 +- 1.5 * IQR(四分位数间距),可在 Wikipedia 上找到

由于我有两个大小相同的独立列表(例如 x,y),因此有必要从列表 x 中删除异常值,并从列表 y 中删除具有相同索引的元素,或者压缩列表并对其进行处理。

在确定传单方面需要改进的建议:

xy = list(zip(x,y))
xy = [(i,j) for i, j in xy\
    if (1. Quartile - 1.5 IQR) < i < (3. Quartile + 1.5 IQR)]
bp.append(ax.scatter(\
    list(zip(*xy))[0],\
    list(zip(*xy))[1]))

【问题讨论】:

    标签: python python-3.x matplotlib outliers


    【解决方案1】:

    如果 x 和 y 是 np.array 类型,那么你可以这样做:

    quartile = ...
    IQR = ...
    # Here, I'm guess what you're attempting to do with these equations.
    lower = (1. * quartile - 1.5 * IQR)
    upper = (3. * quartile + 1.5 * IQR)
    idx = np.where( (lower < x) & (x < upper) )
    
    xs_without_outliers = x[idx]
    ys_without_outliers = x[idx]
    
    ax.scatter(xs_without_outliers, ys_without_outliers)
    

    这里,idx 是来自x 的满足给定条件的索引。这样我们就可以得到满足y[idx]条件的x的值为什么对应的值。

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2020-10-29
      • 2015-05-13
      • 2017-05-16
      • 2015-07-27
      相关资源
      最近更新 更多