Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saimadhu-polamuri/d83705cfce2289f94da12114227a5d55 to your computer and use it in GitHub Desktop.
Save saimadhu-polamuri/d83705cfce2289f94da12114227a5d55 to your computer and use it in GitHub Desktop.
from sklearn.impute import KNNImputer
from sklearn.datasets import load_diabetes
diabetes = load_diabetes()
X, y = diabetes.data, diabetes.target
# Introduce some missing values in X
missing_mask = np.random.rand(*X.shape) < 0.1
X_missing = X.copy()
X_missing[missing_mask] = np.nan
imputer = KNNImputer(n_neighbors=5)
X_imputed = imputer.fit_transform(X_missing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment