【问题标题】:How can I detect outlier depend on its neighbors with null values. (python, numpy)如何检测异常值取决于其具有空值的邻居。 (蟒蛇,麻木)
【发布时间】:2021-11-06 16:58:52
【问题描述】:

如何检测离群值取决于其邻居。

我尝试检测道路上的车道,但由于路标和其他原因,存在空值(-1)和噪音。 对于 null 值,我将使用此方法进行桥接。

def bridging(ar: np.ndarray):
    v_start = 0
    temp = 0
    latch = False
    for e, v in enumerate(ar):
        if not latch:
            if v == -1:   # enter -1 values
                latch = True
                v_start = e
                temp = ar[e-1]
        if latch:
            if v != -1:
                latch = False
                v_length = e - v_start + 2
                fill_values = np.linspace(temp, v, v_length)
                ar[v_start:e] = fill_values[1:-1]
    return ar

但在应用此方法之前,我必须检测并删除依赖于其邻居的异常值。

我尝试使用 Savitzky Golay Filtering https://scipy-cookbook.readthedocs.io/items/SavitzkyGolay.html 但这不能接受空值。

粗体示例粗体应被检测为异常值([184, -1, -1, -1, 756, 430, 473, 567, 618, 589, 585, 464, 467, 184, -1, 642, -1, 389, 387, -1, 589, 602, 728, 597, 568, 620, 610、548、424、-1、-1、301、-1、-1、-1、-1、637]、[-1、-1、3686、-1、3740、3653、-1、3656、 3633, -1, -1, 3421、3389、3560、-1、-1、-1、3340、3313、-1、3418、3566、 3643、3751、3580、3686、3683、3625、3515、3467、-1、3431、-1、 -1, -1, -1, -1]

【问题讨论】:

  • 你能解释一下是什么让每个粗体项目成为异常值吗?这将使您更清楚您希望差距在识别异常值方面发挥什么作用。 (关于桥接的代码 sn-p 似乎主要是在转移注意力,与异常值本身不太相关。)

标签: python numpy scipy filtering outliers


【解决方案1】:

将 null 替换为 0 https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html 然后执行 Savitzky Golay 过滤。 或者您可以删除 null 仅用于计算 https://numpy.org/doc/stable/reference/generated/numpy.delete.html,执行过滤并在末尾添加 null。

【讨论】:

  • 我保留空值但不删除它的原因是因为值之间的空间很重要(空值越多,离群值越大)。
  • 好的,那你为什么不能用过滤器可以接受的非 nan 替换它呢?
  • 如果我将 null 替换为 0 等特定值,那么它不会影响输出值吗?
猜你喜欢
  • 1970-01-01
  • 2022-10-08
  • 2013-06-09
  • 2019-03-14
  • 1970-01-01
  • 1970-01-01
  • 2021-05-25
  • 2023-04-02
  • 2014-03-15
相关资源
最近更新 更多