0

need to convert sklearn.utils._bunch.Bunch

p=partial_dependence(model, X, features=features, percentiles=(0, 1), grid_resolution=2, kind='average') #sklearn.utils._bunch.Bunch'

to pd.DataFrame, surfing the internet led me to the following:

importance_df = pd.DataFrame([X.columns.tolist(), p.tolist()]).T
importance_df.columns = ['column_name', 'pdp_importance']
importance_df = importance_df.sort_values('pdp_importance', ascending=False)
print(importance_df)

compiler throws an error:

   Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_bunch.py in __getattr__(self, key)
     34         try:
---> 35             return self[key]
     36         except KeyError:

KeyError: 'tolist'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
2 frames
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_bunch.py in __getattr__(self, key)
     35             return self[key]
     36         except KeyError:
---> 37             raise AttributeError(key)
     38 
     39     def __setstate__(self, state):

AttributeError: tolist

I tried to find information on the Internet but without success

0 Answers0