Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example to docstring of outlier_remover #639

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions sklego/preprocessing/outlier_remover.py
Original file line number Diff line number Diff line change
@@ -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)
```
anopsy marked this conversation as resolved.
Show resolved Hide resolved
"""
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
anopsy marked this conversation as resolved.
Show resolved Hide resolved
-------
```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)