2021-06-18

#识别和处理异常值
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-2
s)) #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())

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值