From 40ee9c7b54784c4028229634e3d2e219065a7430 Mon Sep 17 00:00:00 2001 From: Magdalena Date: Sat, 23 Mar 2024 15:49:07 +0100 Subject: [PATCH 1/2] Added example to docstring of outlier_remover --- sklego/preprocessing/outlier_remover.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sklego/preprocessing/outlier_remover.py b/sklego/preprocessing/outlier_remover.py index d9167c923..8dcc5337b 100644 --- a/sklego/preprocessing/outlier_remover.py +++ b/sklego/preprocessing/outlier_remover.py @@ -42,6 +42,24 @@ def fit(self, X, y=None): ------- self : OutlierRemover The fitted transformer. + + Example + ------- + ```py + from sklego.preprocessing import OutlierRemover + from sklearn.ensemble import IsolationForest + + np.random.seed(0) + X = np.random.randn(10000, 2) + + isolation_forest = IsolationForest() + isolation_forest.fit(X) + detector_preds = isolator_forest.predict(X) + + outlier_remover = OutlierRemover(isolation_forest, refit=True) + outlier_remover.fit(X) + X_trans = outlier_remover.transform_train(X) + ``` """ self.estimator_ = clone(self.outlier_detector) if self.refit: @@ -61,6 +79,23 @@ def transform_train(self, X): ------- np.ndarray of shape (n_not_outliers, n_features) The data with the outliers removed, where `n_not_outliers = n_samples - n_outliers`. + Example + ------- + ```py + from sklego.preprocessing import OutlierRemover + from sklearn.ensemble import IsolationForest + + np.random.seed(0) + X = np.random.randn(10000, 2) + + isolation_forest = IsolationForest() + isolation_forest.fit(X) + detector_preds = isolator_forest.predict(X) + + outlier_remover = OutlierRemover(isolation_forest, refit=True) + outlier_remover.fit(X) + X_trans = outlier_remover.transform_train(X) + ``` """ check_is_fitted(self, "estimator_") predictions = self.estimator_.predict(X) From a3c6b8806e8fd6f7e9d0caa9eb7c416902b1a356 Mon Sep 17 00:00:00 2001 From: Magdalena Anopsy <74981211+anopsy@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:33:57 +0100 Subject: [PATCH 2/2] Update sklego/preprocessing/outlier_remover.py Co-authored-by: vincent d warmerdam --- sklego/preprocessing/outlier_remover.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sklego/preprocessing/outlier_remover.py b/sklego/preprocessing/outlier_remover.py index 8dcc5337b..c073927e7 100644 --- a/sklego/preprocessing/outlier_remover.py +++ b/sklego/preprocessing/outlier_remover.py @@ -58,7 +58,6 @@ def fit(self, X, y=None): outlier_remover = OutlierRemover(isolation_forest, refit=True) outlier_remover.fit(X) - X_trans = outlier_remover.transform_train(X) ``` """ self.estimator_ = clone(self.outlier_detector)