python中非法的准则_拉依达准则去除异常数据

1.Concept

拉依达准侧(Pau’ta Criteron)是先假设一组数据中只含有随机误差,首先按照一定准侧计算标准偏差,按照一定概率确定一定区间,认为不在这个区间的为异常值。

使用数据类型:数据呈正太分布或者近似正太分布。

2.举例实验

该实验中使用正太分布函数确定区间,认为剩余误差超过3 σ

\sigmaσ为异常值。

python 代码实验:

# encoding:utf-8

'''

@Author:noodles

2020-7-25 17:00:48

'''

import math

import matplotlib.pyplot as plt

import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签

plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号

def pdf(x, mu, sigma):

y = (1.0 / math.sqrt(2 * math.pi * sigma)) * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))

return y

if __name__ == '__main__':

# generate random num tested

src_data = np.random.randn(100)

src_data[99] = 5 # add one outliers

x = np.sort(src_data)

# step1: get mean

mu = x.mean()

# step2: get standard deviation

sigma = x.std()

# plot histgram of its distribution

y = pdf(x, mu, sigma)

# step3: residual error

RE = abs(x - mu)

# step4: remove outliers

good_x = []

outliers = []

for i, j in zip(RE, x):

if i < 3 * sigma:

good_x.append(j)

else:

outliers.append(j)

good_x = np.array(good_x)

good_mu = good_x.mean()

good_sigma = good_x.std()

good_y = pdf(good_x, good_mu, good_sigma)

plt.plot(x, y, c='b', label=u'原始值')

plt.plot(good_x, good_y, c='r', label=u'去除异常值后数据')

plt.title('Normalization distribution curve')

plt.legend()

plt.show()

print('the outliers removed:',outliers)

实验结果:

bfa1d42a800cd3b6925b68872850e41a.png

1c3c4bb0d4c9f641aad495fcb8c34e6d.png

3.Couclusion

使用Pauta准侧第一步你要能够确定你的数据符合正太分布,或者能够转化为正太分布,其次根据自己的需要合理选择不同的概率分布函数。

4.Reference

https://baike.baidu.com/item/%E6%8B%89%E4%BE%9D%E8%BE%BE%E5%87%86%E5%88%99/5678473?fr=aladdin

原文链接:https://blog.csdn.net/huhu123444/article/details/107581218

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
拉依达准则(Pau'ta Criteron)是一种用于识别异常值的统计方法。该方法首先假设数据只包含随机误差,然后根据一定的准则计算标准偏差,并基于一定的概率确定一个区间。如果数据点不在这个区间内,就被认为是异常值。在Python,可以使用统计库的函数来实现拉依达准则。 一个实现拉依达准则Python代码示例如下: ```python import numpy as np def outlier_detection(data): mean = np.mean(data) std = np.std(data) lower_bound = mean - 3 * std upper_bound = mean + 3 * std outliers = [x for x in data if x < lower_bound or x > upper_bound] return outliers # 示例数据 data = [1222, 87, 77, 92, 68, 80, 78, 84, 77, 81, 80, 80, 77, 92, 86, 76, 80, 81, 75, 77, 72, 81, 72, 84, 86, 80, 68, 77, 87, 76, 77, 78, 92, 75, 80, 78, 123, 3, 1223, 1232] outliers = outlier_detection(data) print("拉依达准则检测到的异常值如下:") print(outliers) ``` 以上代码会输出拉依达准则检测到的异常值,即不在平均值-3标准差和平均值+3标准差之间的数据点。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python:使用拉依达准则(3σ准则)剔除excel表异常数据](https://blog.csdn.net/weixin_43996337/article/details/120830794)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [【python 机器学习】正态分布检验以及异常值处理3σ原则](https://blog.csdn.net/u013421629/article/details/103870567)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酥牧奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值