码迷,mamicode.com
首页 > 其他好文 > 详细

2.9 清理异常值

时间:2017-02-26 19:28:53      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:show   via   axis   return   mod   otherwise   dia   array   hold   

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 清理异常值

标签:show   via   axis   return   mod   otherwise   dia   array   hold   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!