【发布时间】:2018-09-26 00:50:16
【问题描述】:
就个人知识而言,我一直在尝试除均值/中值/众数之外的不同插补方法。到目前为止,我能够尝试 KNN、MICE、中值插补方法。有人告诉我,也可以通过聚类方法进行插补,我的互联网搜索找到了一个包,它只找到了研究论文。
我在 Iris 数据集上运行这些插补方法,故意在其中创建缺失值(因为 Iris 没有缺失值)。我对其他方法的做法如下:
data = pd.read_csv("D:/Iris_classification/train.csv")
#Shuffle the data and reset the index
from sklearn.utils import shuffle
data = shuffle(data).reset_index(drop = True)
#Create Independent and dependent matrices
X = data.iloc[:, [0, 1, 2, 3]].values
y = data.iloc[:, 4].values
#train_test_split
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 50, random_state = 0)
#Standardize the data
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
#Impute missing values at random
prop = int(X_train.size * 0.5) #Set the % of values to be replaced
prop1 = int(X_test.size * 0.5)
a = [random.choice(range(X_train.shape[0])) for _ in range(prop)] #Randomly choose indices of the numpy array
b = [random.choice(range(X_train.shape[1])) for _ in range(prop)]
X1_train[a, b] = np.NaN
X1_test[c, d] = np.NaN
然后对于 KNN 插补,我已经完成了
X_train_filled = KNN(3).complete(X_train)
X_test_filled = KNN(3).complete(X_test
有没有办法通过聚类方法来估算缺失值? 此外,当 StandardScaler() 中有 NaN 值时,它也不起作用。还有其他方法可以标准化数据吗?
【问题讨论】:
-
它对你有用吗?
-
我不确定您提供的答案是否是我正在寻找的答案。在我看来,如果我没记错的话,它的归责是卑鄙的。
标签: python machine-learning imputation