Ekeany / Boruta-Shap

A Tree based feature selection tool which combines both the Boruta feature selection algorithm with shapley values.
MIT License
559 stars 86 forks source link

transform function for sklearn compatibility #113

Closed jckkvs closed 1 year ago

jckkvs commented 1 year ago

What does this PR do?

for sklearn compatibility. It enabled below.

from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestRegressor from BorutaShap import BorutaShap
from sklearn.model_selection import cross_val_predict

pipe = Pipeline(steps=[("selector", BorutaShap()), 
                              ("Regressor", RandomForestRegressor())])
pipe.fit(X,y)

Problem

cross_val_predict is not supported yet


~\Anaconda3\envs\lib\site-packages\sklearn\pipeline.py in _fit_transform_one(transformer, X, y, weight, message_clsname, message, **fit_params)
    891             res = transformer.fit_transform(X, y, **fit_params)
    892         else:
--> 893             res = transformer.fit(X, y, **fit_params).transform(X)
    894 
    895     if weight is None:

AttributeError: 'NoneType' object has no attribute 'transform'

The reason for this is that BorutaSHAP does not implement get_params and set_params, so clone(BorutaSHAP()) does not work.