def Chauvenet(v):
c = {5:1.65, 6:1.73, 7:1.8, 8:1.86, 9:1.92, 10:1.96, 11:2, 12:2.03}
n = len(v)
ave = getAve(v)
stdDev = getStdDev(v)
if len(v) < 5:
print("数据少于5个,请检查")
else:
Xmin = ave - (c[n]*stdDev)
Xmax = ave + (c[n]*stdDev)
nv = []
bv = []
for i in range(n):
if Xmin < v[i] < Xmax:
nv.append(v[i])
else:
bv.append(v[i])
if len(bv) == 0:
print(str(v))
print("该数据没有坏值")
print()
return nv
else:
print(str(v))
print("该数据有坏值,分别是:")
for i in range(len(bv)):
print(bv)
print()
return Chauvenet(nv)
下面是最简单的实现方法。
def Chauvenet(v):
c = {5:1.65, 6:1.73, 7:1.8, 8:1.86, 9:1.92, 10:1.96, 11:2, 12:2.03}
if len(v) < 5:
return []
Xmin = getAve(v) - (c[len(v)]*getStdDev(v))
Xmax = getAve(v) + (c[len(v)]*getStdDev(v))
nv = [i for i in v if Xmin < i for i in v if Xmin > i or i > Xmax]
if bv == []:
return nv
return nv+Chauvenet(nv)