首页 > 代码库 > 2.9 清理异常值
2.9 清理异常值
import numpy as np import matplotlib.pyplot as plt def is_outlier(points,threshold=3.5): ‘‘‘Return a boolen array with True if points are out liers and Fa;se otherwise data point with a modified zscore fjdsklfadlkfa dfjalskerwwerwerwerwe rw :parameterwe :raisewer :keyworder we r we r etr xiaxiede :returne 2wwe :returnff fwr wr ‘‘‘ if len(points.shape) == 1: points = points[:, None] median = np.median(points, axis=0) diff = np.sum((points-median)**2, axis=-1) diff = np.sqrt(diff) med_abs_deviation = np.median(diff) modified_z_score=0.6745*diff/med_abs_deviation return modified_z_score>threshold x=np.random.random(100) buckets=50 x=np.r_[x, -49, 95, 100, -100] filtered=x[~is_outlier(x)] plt.figure() plt.subplot(211) plt.hist(x,buckets) plt.xlabel(‘Raw‘) plt.subplot(212) plt.hist(filtered,buckets) plt.xlabel(‘Cleaned‘) plt.show()
2.9 清理异常值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。