Repository navigation
Support string categorical features in PartialDependence - #684
raashish1601 wants to merge 2 commits into
Conversation
Signed-off-by: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #684 +/- ##
==========================================
+ Coverage 67.32% 67.38% +0.05%
==========================================
Files 77 77
Lines 11739 11745 +6
==========================================
+ Hits 7903 7914 +11
+ Misses 3836 3831 -5 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The failing jobs don't come from this change: the scheduled interpret-CI runs on main fail the same way (e.g. run 37461974875 on 560f8dd). The test jobs fail while importing |
There was a problem hiding this comment.
🟢 Approval recommended
The focused changes preserve numeric behavior, include regression coverage, and have no identified blocking issues.
No open issues 🎉
What changed in this PR
Enables PartialDependence to handle string categorical features, addressing #217 while preserving the existing numeric conversion path.
Changes:
- Retains mixed-type data when whole-matrix float conversion fails.
- Converts continuous columns individually for grid and density calculations.
- Adds regression coverage comparing categorical and continuous curves against model predictions.
| File | Description |
|---|---|
| python/interpret-core/tests/blackbox/test_partialdependence.py | Tests partial dependence curves with mixed string and numeric features. |
| python/interpret-core/interpret/blackbox/_partialdependence.py | Adds mixed-type fallback and per-column numeric conversion. |
Review effort: Balanced
Fixes #217
PartialDependenceconverted the whole data matrix to float64 before building the curves, so any string categorical column (for example a model that is a pipeline with aOneHotEncoder) failed withValueError: could not convert string to float, with or withoutfeature_types._gen_pdpalready uses the unique values as grid points for nominal and ordinal features, so the change only keeps the data as an object array when it can't be converted, and converts each continuous column to float on its own. Numeric data still goes through the float64 path as before.Tests: added
tests/blackbox/test_partialdependence.py, which checks the curves for a string feature and a continuous feature against the mean prediction with that feature set to each grid value. It fails on main and passes with this change. ruff format is clean; ruff check reports only the three warnings that are already on main in_partialdependence.py.