multivariate feature imputation

Solutions on MaxInterview for multivariate feature imputation by the best coders in the world

showing results for - "multivariate feature imputation"
Martina
24 Aug 2017
1# Multivariate feature imputation
2
3import numpy as np
4from sklearn.experimental import enable_iterative_imputer
5from sklearn.impute import IterativeImputer
6imp = IterativeImputer(max_iter=10, random_state=0)
7imp.fit([[1, 2], [3, 6], [4, 8], [np.nan, 3], [7, np.nan]])
8# IterativeImputer(random_state=0)
9X_test = [[np.nan, 2], [6, np.nan], [np.nan, 6]]
10# the model learns that the second feature is double the first
11print(np.round(imp.transform(X_test)))
12# [[ 1.  2.]
13#  [ 6. 12.]
14#  [ 3.  6.]]