sklego/outlier-remover-before-model
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| scikit-lego | error | none, edit by hand | All versions |
OutlierRemover drops rows of X and leaves y whole, so the model after it raises ValueError. Drop the outliers from X and y before the pipeline.
pipeline = make_pipeline(OutlierRemover(IsolationForest(), refit=True), LinearRegression())pipeline.fit(X, y)kept = IsolationForest().fit_predict(X) != -1model = LinearRegression().fit(X[kept], y[kept])What the rule reports
Section titled “What the rule reports”The rule reports OutlierRemover in a pipeline that also holds a step named like a regressor or a
classifier. The remover drops rows of X while the pipeline is fitted, and a scikit-learn pipeline
can't drop the same rows of y.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
fit raised ValueError "Found input variables with inconsistent numbers of samples: [328, 400]".
A pipeline that ended in KMeans, which reads no y, fitted on the 328 kept rows, and the rule
leaves it alone.
Diagnostic message
Section titled “Diagnostic message”OutlierRemover drops rows of X and leaves y whole, so the model after it raises ValueError "Found input variables with inconsistent numbers of samples: [328, 400]". Drop the outliers from X and y before the pipeline, with the detector's fit_predict as a mask.See all rules in the scikit-lego pack.