我的原始数据集形状是(790215,20)
,其中包含的功能大约有60-80%缺少值。我决定使用scikit learn的KNI计算机,如下所示
import pandas as pd
from sklearn.impute import KNNImputer
# Loading the data
dataset = pd.read_csv('Dataset.csv')
# To avoid 'MemoryError' imputing individually
#Loading the first feature
X = dataset.iloc[:,0].values
#Imputing with default parameters
imputer = KNNImputer()
#Reshaping to meet the dimensional requirement
X_imp = imputer.fit_transform(X.reshape(1,-1))
现在X_imp
的形状是(1,729026)
我不确定我做错了什么。为什么790215改为729026
更新:
{
X.reshape(1,-1).shape
是(1,790215)
X.reshape(1,-1)
是array([[ nan, 97., 89., ..., 140., 120., 115.]])
你使用
reshape
的方式就是问题所在。您已经通过给出.reshape(1, -1)
将数据转换为单个数据点。表示一行790215列。因此,在转换KNIMPUTER时,会删除只有nan
值的列。这就是下降的原因相反,您需要使用
.reshape(-1,1)
,这将使它成为790215行和1列注意:对KNIMPUTER使用单一功能可能无法正常工作。最好一次使用3-5个功能。你也可以看看
SimpleImputer
相关问题 更多 >
编程相关推荐