为什么它显示空数组?

问题描述

我正在使用 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))

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...