python剔除列表异常值_Python:拒绝列表中的异常值(序列)

你可以做的是计算数据的前后梯度,假设步长为1。离群值是那些条件适用的元素:向后和向前的坡度没有相同的标志:趋势变化

后向梯度的绝对值大于左邻域绝对值的1%

我对你的解释是,这两种说法都必须是真的。在

让f成为数据的一维numpy数组。在f=np.array([

0.0937,

0.0934,

0.0933,

0.0931,

0.0933,

0.0936,

0.1091, #< == outlier,

0.0938,

0.0945,

0.0949,

0.0956,

0.1082,

0.1065, #< == outlier since -,

0.1123,

0.1198

])

bg = 0.0*f # backward gradient, we want them to have the same size as f

fg = 0.0*f # forward gradient, we want them to have the same size as f

bg[1:] = f[1:]-f[:-1]

fg[:-1] = f[1:]-f[:-1]

outliers = (bg*fg<0) * np.hstack((False, np.where(np.abs(bg[1:])>0.01*np.abs(f[:-1]),True,False) ))

# You don't want to remove an element and the next

outliers[1:] = outliers[1:]*np.where( outliers[:-1], False, True )

print 'Outliers = ', f[outliers]

print 'Good = ', f[np.where( outliers, False, True)]

我用你的数据做了这个例子,只要用任何东西替换f。在

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值