如何解决为什么它显示空数组?
我正在使用 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),)
解决方法
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))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。