Fix DataFrame feature name warnings in sklearn wrapper models (#540)#692
Fix DataFrame feature name warnings in sklearn wrapper models (#540)#692ugbotueferhire wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8cdccc56c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Hi @yzhao062, I’ve addressed the Codex review feedback on this PR and pushed the fixes. The latest commit preserves sparse input support in LOF.decision_function and makes the pandas DataFrame regression test skip cleanly when pandas is unavailable. Could you please take another look and merge when you have a chance? Thank you! |
All Submissions Basics:
All Submissions Cores:
Closes #540
What does this PR do?
Adds
X = check_array(X)todecision_function()in four sklearn-wrapper models (IForest,OCSVM,LOF,GMM) that were missing input validation. This prevents theUserWarning: X has feature names, but <Model> was fitted without feature nameswarning when using pandas DataFrames.Root cause:
fit()already callscheck_array(X), which strips DataFrame column names before fitting the underlying sklearn estimator. Butdecision_function()was passing the raw DataFrame directly to sklearn at predict time, causing a feature-name mismatch warning.Three other wrapper models (
MCD,PCA,HDBSCAN) already hadcheck_array(X)in theirdecision_function()and were unaffected.Changes
pyod/models/iforest.py— addX = check_array(X)indecision_function()pyod/models/ocsvm.py— samepyod/models/lof.py— samepyod/models/gmm.py— samepyod/test/test_iforest.py— add regression testtest_dataframe_no_feature_name_warning