Skip to content

[BUG]: "feature_selection_estimator" is not working when using estimater(not string) #3556

@lon-ryu

Description

@lon-ryu

pycaret version checks

Issue Description

Hello!
I set feature_selection_estimator to use LGBClassifier(importance_type='gain') for feature selection, but an error occurred.
When I checked the code, it seems that the value of feature_selection_estimator that I set was only used for error checking in _feature_selection in "preprocessor.py" and was not used anywhere else.

Reproducible Example

exp.setup(data=train, target='tg', feature_selection=True, feature_selection_estimator=LGBMClassifier(importance_type='gain'))

Expected Behavior

Any estimator that can obtain feature_importance can be used to select features

Actual Results

Traceback (most recent call last):
  File "C:\xxx\plugins\python-ce\helpers\pydev\pydevd.py", line 1491, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\xxx\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/xxx/ensemble_learning_2.py", line 158, in <module>
    exp.setup(
  File "C:\Users\xxx\venv310\lib\site-packages\pycaret\classification\oop.py", line 880, in setup
    self._feature_selection(
  File "C:\Users\xxx\venv310\lib\site-packages\pycaret\internal\preprocess\preprocessor.py", line 993, in _feature_selection
    estimator=fs_estimator,
UnboundLocalError: local variable 'fs_estimator' referenced before assignment

Installed Versions

PyCaret 3.0.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions