发现异常的值在一个阵列,列表阵列、异常、发现、列表

2023-09-11 03:50:38 作者:愿你找到你命中注定的那个她

我在数组形式的销售统计数据calc下标准差,或平均从这些数据。

I have sales statistic data in array form to calc standard deviation or average from this data.

stats = [100, 98, 102, 100, 108, 23, 120] 

让说,正常情况下, 23 显然是一个特例+ -20%差是。

let said +-20% differential is normal situation, 23 is obviously a special case.

什么是最好的算法(在任何语言,伪或原则)找到这个不寻常的价值呢?

what's the best algorithm (in any language, pseudo or any principle) to find this unusual value?

推荐答案

您可以将它们转换为 Z分数并查找异常值。

You could convert them to Z-scores and look for outliers.

>>> import numpy as np
>>> stats = [100, 98, 102, 100, 108, 23, 120]
>>> mean = np.mean(stats)
>>> std = np.std(stats)
>>> stats_z = [(s - mean)/std for s in stats]
>>> np.abs(stats_z) > 2
array([False, False, False, False, False,  True, False], dtype=bool)