【发布时间】:2020-06-20 10:05:25
【问题描述】:
我的原始数据集形状是 (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.]])
【问题讨论】:
-
出于调试目的,能否打印 X.shapea 和 X.reshape(1, -1)?
标签: python pandas numpy scikit-learn