Should DropHighPSIFeatures count missing values in a separate bin?

Open
#1,140 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active

Research direction

Read the existing DropHighPSIFeatures implementation and its PSI tests, then trace how missing rows are handled when bin proportions are calculated. Add coverage for the proposed opt-in missing_values="include" behavior, including the example’s rising missing rate. Done when missing values form their own bin using all rows in each period and the default ignore behavior remains intact.

Written by the indexing model from the issue text.

Description

Following up on #883 and #1110. Would you be open to an opt-in missing_values="include" mode in DropHighPSIFeatures?

In this example, A and B are equally frequent among observed rows in both periods, but the missing rate rises from 10% to 50%. Ignoring missing rows gives PSI = 0. Counting them in a separate bin gives PSI ≈ 0.87889.

import pandas as pd
from feature_engine.selection import DropHighPSIFeatures

basis = ["A"] * 9 + ["B"] * 9 + [None] * 2
test = ["A"] * 5 + ["B"] * 5 + [None] * 10
X = pd.DataFrame({"segment": basis + test})

for data in (X, X.fillna("__MISSING__")):
    selector = DropHighPSIFeatures(
        variables=["segment"], cut_off=19, missing_values="ignore"
    ).fit(data)
    print(float(selector.psi_values_["segment"]))

The second run uses a placeholder category to show the desired result with the existing API. With the proposed option, missing rows would go into their own bin and each period's bin proportions would use all rows.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from feature-engine/feature_engine

All issues in feature-engine/feature_engine

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.