异常值检测功能

时间:2017-07-05 03:20:00

标签: python-3.x

我已经创建了检测数据集异常值的函数,但是当我应用它时会显示错误,代码&错误如下所示。

功能

def find_outlairs_tukey(x):
    q1 = np.percentile(x, 25)
    q3 = np.percentile(x, 75)
    iqr = q3 - q1
    floor = q1 - 1.5*iqr
    ceiling = q3 + 1.5*iqr
    outlair_indices = list(x.index[(x < floor) | (x > ceiling)])
    outlair_values = list(x[outlair_indices])

应用

LotFrontage_indices, LotFrontage_values = find_outlairs_tukey(house_1['LotArea'])
print(np.sort(turkey_values))

错误

TypeError                                 Traceback (most recent call last)
<ipython-input-208-4923f848f510> in <module>()
----> 1 LotFrontage_indices, LotFrontage_values = find_outlairs_tukey(house_1['LotArea'])
      2 print(np.sort(turkey_values))

TypeError: 'NoneType' object is not iterable

1 个答案:

答案 0 :(得分:0)

添加返回功能:

return outlair_indices, outlair_values