首页 > 其他 > 详细

2.9 清理异常值

时间:2017-02-26 19:28:53      阅读:284      评论:0      收藏:0      [点我收藏+]
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 清理异常值

原文:http://www.cnblogs.com/boooobao/p/6445354.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!