Created
October 18, 2023 03:15
-
-
Save saimadhu-polamuri/d83705cfce2289f94da12114227a5d55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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