Add `split_col` (as a series/array) as optional argument to the `fit` method of `DropHighPSIFeatures`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python, scikit-learn
- Domain
- machine-learning
Research direction
Start by reading the DropHighPSIFeatures implementation and its existing tests to understand how split_col currently selects the two dataframe splits. Check how scikit-learn metadata routing is requested and passed to estimators. Done means fit accepts a series or array as split_col, the pipeline example can pass it as metadata, and tests cover this behavior without requiring it in the feature dataframe.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
DropHighPSIFeatures currently takes one of the input features ad uses it to split the dataframe in two, if no split_col column is provided, it will use the order of the dataframe.
This kind of behavior forces the user of this class to either:
- Have the split_col as a feature of the input dataframe.
- Set
split_colas dataframe index.
Both options can sometimes be not ideal because more often than not, the split_col is not a column to generate features on, but it is just metadata. Other pipeline components before DropHighPSIFeatures might not be very happy to receive split_col as part of the input Dataframe and it is needed to deal with the split_col there to explicitly ignore it.
Example of current workflow:
from sklearn.pipeline import make_pipeline
from feature_engine.selection import DropFeatures, DropHighPSIFeatures
from sklearn.linear_model import LogisticRegression
import pandas as pd
df = pd.DataFrame(
{
"feat": [1, 2, 1, 2, 1] * 5,
"date": ["2025-01-01", "2025-01-02", "2025-01-03", "2025-01-04", "2025-01-05"] * 5,
"target": [1, 0, 1, 0, 1] * 5,
}
)
pipeline = make_pipeline(
DropHighPSIFeatures(
threshold=0.95,
split_col="date",
),
# Here we are dropping the date column
# because it is not needed for the model
DropFeatures(features_to_drop=["date"]),
LogisticRegression(),
)
pipeline.fit(df[["feat", "date"]], df["target"])
Describe the solution you'd like
To prevent this from happening, we might add the split_col (in the form of a series or array) to the fit method of DropHighPSIFeatures.
With this change, the user of DropHighPSIFeatures has the option of passing the split column as metadata using the new sklearn metadata API (more of it here) without having to keep the split column as a feature of the input dataframe.
Example of workflow I would like to have:
import sklearn
from sklearn.pipeline import make_pipeline
from feature_engine.selection import DropHighPSIFeatures
from sklearn.linear_model import LogisticRegression
import pandas as pd
sklearn.set_config(enable_metadata_routing=True)
df = pd.DataFrame(
{
"feat": [1, 2, 1, 2, 1] * 5,
"date": ["2025-01-01", "2025-01-02", "2025-01-03", "2025-01-04", "2025-01-05"] * 5,
"target": [1, 0, 1, 0, 1] * 5,
}
)
pipeline = make_pipeline(
DropHighPSIFeatures(
threshold=0.95,
# Here we tell sklearn components that split col needs to be passed
# only to the fit method of DropHighPSIFeatures, and not to all of the
# other pipeline components
).set_fit_request(split_col=True),
LogisticRegression(),
)
# No need to keep the date column to the X dataframe anymore
pipeline.fit(df[["feat"]], df["target"], split_col=df["date"])
Describe alternatives you've considered
Set split_col as dataframe index is a potential solution to the issue, but feels more of a hack than a solution.
Additional context
N/A
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 391
- Avg merge
- 11h 34m
- Merged PRs (30d)
- 11
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from feature-engine/feature_engine
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
feature-engine/feature_engine#1141 · 1 comment ·
Maintainers usually reply within 1 day
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
feature-engine/feature_engine#393 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
feature-engine/feature_engine#1140 · 2 comments ·
Maintainers usually reply within 1 day
-
CategoricalImputer fails when fill_value is already a categoryPossibly taken @AryanRG claimed this 12 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 18/100
feature-engine/feature_engine#1113 · 2 comments ·
Maintainers usually reply within 1 day
-
OneHotEncoder loses a dummy name when it matches an encoded input columnPossibly taken @Aadrit555 claimed this 7 days ago. Open
Difficulty 3/5 Half a day Newbie friendliness 25/100
feature-engine/feature_engine#1106 · 1 comment ·
Maintainers usually reply within 1 day
All issues in feature-engine/feature_engine
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
MakazhanAlpamys/Soup#3589 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-connect#1266 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
biosustain/growthcurves_app#89 ·
Maintainers usually reply within 1 day
-
`LogProxyConsumer._on_relation_departed` raises `APIError` when the promtail service does not existOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
canonical/loki-k8s-operator#695 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day