From b5fea0ea9b28cde1321185aeaedaa7eaa3cfcfed Mon Sep 17 00:00:00 2001 From: Moulay Idris DAOUADI <moulay_idris.daouadi@doctorant.uca.fr> Date: Mon, 26 Feb 2024 20:22:03 +0000 Subject: [PATCH] Upload New File --- imputation_knn.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 imputation_knn.py diff --git a/imputation_knn.py b/imputation_knn.py new file mode 100644 index 0000000..0855f3d --- /dev/null +++ b/imputation_knn.py @@ -0,0 +1,24 @@ +# stdlib +from typing import Any + +# third party +import numpy as np +from sklearn.impute import KNNImputer + + +class KNNImputation: + def __init__(self, **kwargs: Any) -> None: + super().__init__() + + self._model = KNNImputer(**kwargs) + + def fit(self, X: np.ndarray, *args: Any, **kwargs: Any) -> "KNNImputation": + self._model.fit(np.asarray(X), *args, **kwargs) + + return self + + def transform(self, X: np.ndarray) -> np.ndarray: + return self._model.transform(np.asarray(X)) + + def fit_transform(self, X: np.ndarray) -> np.ndarray: + return self.fit(X).transform(X) -- GitLab