Accessing the feature_importances_ of the imblearn EasyEnsembleClassifier

32 views Asked by At

I am Chere and I am new here. Please how do I get the feature_importances_ of the EasyEnsembleClassifier from imblearn within a pipeline with AdaBoost Classifier as its estimator? My pipeline looks like this:

from sklearn.pipeline import make_pipeline, Pipeline
from sklearn.ensemble import AdaBoostClassifier
from imblearn.ensemble import EasyEnsembleClassifier

pipe6 = Pipeline([ ('ct_step', ct), ('model', EasyEnsembleClassifier(n_estimators=10, replacement=True, sampling_strategy=0.005, base_estimator=AdaBoostClassifier())) ]).

I tried this:

pipe6.named_steps['model'].feature_importances_
fd6 = pd.DataFrame({'Feature_names':pipe6.named_steps['ct_step'].get_feature_names_out(),'Importances':pipe6.named_steps['model'].base_estimator.feature_importances_})
fd6['Importances'] = fd6['Importances'].apply(lambda x: format(x, '.5f'))
fd6 = fd6.drop(fd6[fd6.Importances < '0.00001'].index )
fd6 = fd6.sort_values(by='Importances', ascending=False)
fd6 = fd6.replace({"pp_num__": "", "pp_cat__": ""}, regex=True)
1

Display the feature importance table

print('FEATURE IMPORTANCE TABLE')
print(fd6)

But keep getting AttributeError: Pipeline has no object attribute 'feature_importances_ Please I need help

0

There are 0 answers