diff --git a/sklego/preprocessing/outlier_remover.py b/sklego/preprocessing/outlier_remover.py index d9167c923..c073927e7 100644 --- a/sklego/preprocessing/outlier_remover.py +++ b/sklego/preprocessing/outlier_remover.py @@ -42,6 +42,23 @@ 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) + ``` """ self.estimator_ = clone(self.outlier_detector) if self.refit: @@ -61,6 +78,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)