Skip to content

Instantly share code, notes, and snippets.

@kavinvin
Last active December 28, 2017 09:59
Show Gist options
  • Save kavinvin/571c6f5c90a367bcbd1bf503014db1a5 to your computer and use it in GitHub Desktop.
Save kavinvin/571c6f5c90a367bcbd1bf503014db1a5 to your computer and use it in GitHub Desktop.
imputation
from sklearn.preprocessing import Imputer
import numpy as np
imputer = Imputer(strategy='mean', axis=0)
imputer.fit(np.array([[4, 400, 30],
[5, 300, 25]]))
print(imputer.statistics_)
# [4.5 350 27.5]
print(imputer.transform([[4, 800, np.nan],
[np.nan, 500, 40],
[2, np.nan, 32]]))
# [[4 800 27.5],
# [4.5 500 40],
# [2 350 32]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment