When trying to call the function "shap.decision_plot", I get the aforementioned error. It seems that it is an issue related to the use of "to_list()".
explainer = shap.TreeExplainer(rf_model)
shap.decision_plot(explainer.expected_value[1], explainer.shap_values(X6.iloc[64])[1], X6.iloc[64])
AttributeError Traceback (most recent call last)
in
----> 1 shap.decision_plot(explainer.expected_value[1], explainer.shap_values(X6.iloc[64])[1], X6.iloc[64])~\AppData\Local\Continuum\anaconda3\lib\site-packages\shap\plots\decision.py in decision_plot(base_value, shap_values, features, feature_names, feature_order, feature_display_range, highlight, link, plot_color, axis_color, y_demarc_color, alpha, color_bar, auto_size_plot, title, xlim, show, return_objects, ignore_warnings, matplotlib)
323 elif str(type(features)) == "":
324 if feature_names is None:
--> 325 feature_names = features.index.to_list()
326 features = features.values
327 elif isinstance(features, list):AttributeError: 'Index' object has no attribute 'to_list'
Any help would be really appreciated.
Thank you very much.
Regards,
David
@floidgilbert thoughts?
@davidgar: Thanks for including the trace. Please execute the following and send me the output.
f = X6.iloc[64]
print(type(f.index))
print(len(f.index.to_list()))
Thank you very much @slundberg and @floidgilbert for your help and prompt response.
Please, find attached the screenshot of the output obtained after the execution.
.
You may have an older version of Pandas installed. I suggest upgrading. At some point, the standard method name changed from tolist() to to_list(). If upgrading doesn't work, please run the following script and post the output again.
import pandas as pd
print(pd.__version__)
a = pd.Series(range(4), ['a', 'b', 'c', 'd'])
print(a.index.tolist())
print(a.index.to_list())
Thank you again @floidgilbert . As you suggested, I upgraded Pandas and (after some dependencies issues), the original "tolist"-"to_list()" issue seems to be fixed.
I have not been able to completely check as I'm getting a new error message when calling "TreeExplainer" under a Random Forest Classifier model.
I'm not sure if I should open a new issue. Anyway, I'm sending a screenshot of this new error.
Thank you in advance.
seed = 0
rf_params2 = {
'n_jobs': -1,
'n_estimators': 500,
'max_features': 0.3,
'max_depth': 100,
'min_samples_leaf': 2,
'max_features': 'sqrt',
'random_state': seed,
'verbose': 0,
'class_weight': 'balanced'
}
rf_clf2 = ensemble.RandomForestClassifier(**rf_params2)
Glad it worked. As for the new issue, see #928. You will need to install SHAP from the GitHub repository unless you want to wait for the next release. For example: pip install git+https://github.com/slundberg/shap.git
Thank you very much @floidgilbert . Everything is working perfectly fine now.
Thanks for your help and support.
Most helpful comment
You may have an older version of Pandas installed. I suggest upgrading. At some point, the standard method name changed from
tolist()toto_list(). If upgrading doesn't work, please run the following script and post the output again.