Potential issue with Tree Surrogate rules as text
Hi, as discussed when I was building my model interpretation tutorial on the census or adult dataset, the surrogate tree model throws an error when trying to get the rules as text.
Code and data I'm using is in my tutorial: http://nbviewer.jupyter.org/github/dipanjanS/data_science_for_all/blob/master/tds_model_interpretation_xai/Human-interpretable%20Machine%20Learning%20-%20DS.ipynb
Code causing an error (not in the tutorial but the surrogate model code is present)
Note: The model is in the variable surrogate_explainer in the code and works quite well otherwise for visualization and also predictions!
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-231-0d5c9d6ab4fe> in <module>()
----> 1 surrogate_explainer.decisions_as_txt()
C:\Anaconda3\lib\site-packages\skater-1.1.1b5-py3.6.egg\skater\core\global_interpretation\tree_surrogate.py in decisions_as_txt(self, scope, X)
426 """ Retrieve the decision policies as text
427 """
--> 428 tree_to_text(self.__model, self.feature_names, self.__model_type, scope, X)
C:\Anaconda3\lib\site-packages\skater-1.1.1b5-py3.6.egg\skater\core\visualizer\tree_visualizer.py in tree_to_text(tree, feature_names, estimator_type, scope, X)
178 right_nodes = tree.tree_.children_right
179 criterias = tree.tree_.threshold
--> 180 feature_names = [feature_names[i] for i in tree.tree_.feature]
181 values = tree.tree_.value
182
C:\Anaconda3\lib\site-packages\skater-1.1.1b5-py3.6.egg\skater\core\visualizer\tree_visualizer.py in <listcomp>(.0)
178 right_nodes = tree.tree_.children_right
179 criterias = tree.tree_.threshold
--> 180 feature_names = [feature_names[i] for i in tree.tree_.feature]
181 values = tree.tree_.value
182
TypeError: 'NoneType' object is not subscriptable
You can try adding the argument feature_names = list_of_your_feature_names in InMemoryModel. Doing this worked for me!