gpt4 book ai didi

python - Scikit-learn (0.22.1) KNNImputer 返回错误数量的值

转载 作者:行者123 更新时间:2023-12-04 10:27:12 24 4
gpt4 key购买 nike

我的原始数据集形状是 (790215,20)其中包含具有大约 60-80% 缺失值的特征。我决定使用 scikit-learn 的 KNNImputer 如下

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.shape(790215,) X.reshape(1,-1).shape(1,790215) X.reshape(1,-1)array([[ nan, 97., 89., ..., 140., 120., 115.]])

最佳答案

您使用的方式 reshape是问题所在。您已通过提供 .reshape(1, -1) 将数据转换为单个数据点.意思是 1 行,790215 列。因此,在转换 KNNImputer 时删除只有 nan 的列。值。这就是下降的原因。

相反,您需要使用 .reshape(-1,1) ,这将使它成为 790215 行和 1 列。

注意:对 KNNImputer 使用单个功能可能效果不佳。更好的是,您可以一次使用 3-5 个功能。也可以看看SimpleImputer .

关于python - Scikit-learn (0.22.1) KNNImputer 返回错误数量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60584925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com