Skip to content

Instantly share code, notes, and snippets.

@sazio
Created August 29, 2020 12:11
Show Gist options
  • Save sazio/c92e55fb567d48be9bed812cf13aee6b to your computer and use it in GitHub Desktop.
Save sazio/c92e55fb567d48be9bed812cf13aee6b to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn.impute import SimpleImputer
# Missing expected values are Nan, we're using statitistics (mean) to impute
imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
X_train = [[7, 2, 3], [4, np.nan, 6], [10, 5, 9]]
imp_mean.fit(X_train)
X_test = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
print(imp_mean.transform(X_test))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment