【问题标题】:Why its showing empty array?为什么它显示空数组?
【发布时间】:2021-05-07 07:38:50
【问题描述】:

我正在使用 z score 方法去除异常值 ..但是当我设置阈值并打印低于该阈值的数据时,我得到了空数组。 我试过下面的代码。

from scipy import stats
z=np.abs(stats.zscore(df.High))
print(z)

threshold=7
print(np.where(z>7))

它显示以下输出而不是显示一个值的数组。

(array([], dtype=int64),)

【问题讨论】:

  • 显然没有一个值大于 7。
  • 不,有 9,8,7 之类的值。这些值最多为 9
  • 您需要发布原始数据。或导致相同问题的原始数据的样本版本。
  • 应该在stackoverflow上发布数据吗?
  • 您需要发布运行并在运行时重现错误的内容。这包括合并任何必要的输入。

标签: python algorithm machine-learning outliers data-preprocessing


【解决方案1】:

Z-Score 本质上是我的实际标准差的多少 取平均值!

更多关于这个here。您在这里所做的是将您的人口(列包含值)转换为 Z 分数并使用实际值作为阈值,但阈值也应该在 Z 空间中!该值由问题的性质决定。

import matplotlib.pyplot as plt 
import numpy as np 
import pandas as pd 
import seaborn as sns
from scipy import stats 
mu, sigma = 5, 2
array = np.random.normal(mu, sigma, 200)
df = pd.DataFrame(array, columns=["High"]) 
z=np.abs(stats.zscore(df.High))
print("Actual Value Above 7: ", df[df.High>7])
threshold=7
print("Z Score Value Above 7: ", np.where(z>threshold))
######## mapping 7 to Z space
z_threshold = (threshold - df.High.mean())/df.High.std(ddof=0)
print("Z Score Value Above zscore(7): ", np.where(z>z_threshold))

【讨论】:

    猜你喜欢
    • 2014-02-09
    • 2021-03-03
    • 1970-01-01
    • 2022-12-06
    • 2017-06-12
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    相关资源
    最近更新 更多