Skip to main content
 首页 » 编程设计

python之什么是西格玛裁剪你怎么知道什么时候应用它

2025年05月04日14mayingbao

我正在阅读一本关于 Python 数据科学的书,作者应用“sigma-clipping 操作”来删除由于拼写错误引起的异常值。然而,这个过程根本没有解释。

什么是西格玛裁剪?它是否仅适用于某些数据(例如,在书中它用于计算美国的出生率)?

根据正文:

quartiles = np.percentile(births['births'], [25, 50, 75]) #so we find the 25th, 50th, and 75th percentiles 
mu = quartiles[1] #we set mu = 50th percentile 
sig = 0.74 * (quartiles[2] - quartiles[0]) #??? 
 
This final line is a robust estimate of the sample mean, where the 0.74 comes  
from the interquartile range of a Gaussian distribution. 

为什么是 0.74?这有证据吗?

请您参考如下方法:

This final line is a robust estimate of the sample mean, where the 0.74 comes from the interquartile range of a Gaussian distribution.

就是这样,真的......

该代码尝试使用四分位数间距来估计 sigma,以使其对异常值具有鲁棒性。 0.74 是校正因子。计算方法如下:

p1 = sp.stats.norm.ppf(0.25)  # first quartile of standard normal distribution 
p2 = sp.stats.norm.ppf(0.75)  # third quartile 
print(p2 - p1)  # 1.3489795003921634 
 
sig = 1  # standard deviation of the standard normal distribution   
factor = sig / (p2 - p1) 
print(factor)  # 0.74130110925280102 

在标准正态分布 sig==1 中,四分位数间距为 1.35。所以 0.74 是将四分位数间距转换为 sigma 的校正因子。当然,这仅适用于正态分布。