#识别和处理异常值
import numpy as np
import pyplot as plt
a=read(x) #x为你要检查的文件
mu=a.count.mean() #mean value
s=a.counts.std() #standard deviation
print(“标准差异常值上限:”,any(a.counts>mu+2s)) #true
print(“下限:”,any(a.counts<mu-2s)) #false
Q1=a.counts.quartile(0.25)
Q3=a.counts.quartile(0.75)
IQR=Q3-Q1
plt.style.use(‘ggplot’)
a.counts.plot(kind=‘hist’,bins=30,density=Ture)
a.counts.plot(kind=‘kde’)
plot.show()
print(“原始数据”,a.count.describre())
nmsl=Q3+1.5*IQR
print(“临界值为nmsl:”, nmsl)
St=a.counts[a.counts<nmsl].max() # biggest right outlier
print("替换的数据为: ",st)
a.loc[a.counts>nmsl,‘counts’]=st #换outlier
print(“替换后为”, a.counts.describe())
2021-06-18
最新推荐文章于 2021-11-09 20:10:55 发布