def statisticalNoiseReduction(values, std_factor_threshold = 2):
"""
Eliminates outlier values that go beyond a certain threshold.
:param values: The list of elements that are being filtered.
:param std_factor_threshold: Filtering aggressiveness. The bigger the value, the more it filters.
:return: The filtered list.
"""
if len(values) == 0:
return []
valarray = np.array(values)
mean = valarray.mean()
standard_deviation = valarray.std()
# just return if we only got constant values
if standard_deviation == 0:
return values
# remove outlier values
valarray = valarray[(valarray > mean - std_factor_threshold * standard_deviation)
& (valarray < mean + std_factor_threshold * standard_deviation)]
return list(valarray)
评论列表
文章目录