Skip to content

Commit

Permalink
Added example to docstring of outlier_remover (#639)
Browse files Browse the repository at this point in the history
* Added example to docstring of outlier_remover

* Update sklego/preprocessing/outlier_remover.py

Co-authored-by: vincent d warmerdam  <[email protected]>

---------

Co-authored-by: Magdalena <[email protected]>
Co-authored-by: vincent d warmerdam <[email protected]>
  • Loading branch information
3 people authored Mar 23, 2024
1 parent 0e92f3b commit 883922a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions sklego/preprocessing/outlier_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 883922a

Please sign in to comment.