Reputation: 19
I'm trying to use the dtreeviz library to visualize a decision tree, but I’m encountering an error: TypeError: 'int' object is not subscriptable
Here’s the code I’m trying to run:
viz = dtreeviz(modelo_iris,
X_train=x,
y_train=y,
target_name='Tipo_Orquidea',
feature_names=features,
class_names=['Não Orquídea', 'Orquídea'])
viz
However, when I run it, I get the following error message: TypeError: 'int' object is not subscriptable
The traceback shows:
----> 2 viz = dtreeviz(modelo_iris,
--> 254 return model.view(precision, orientation,
--> 335 if self.shouldGoLeftAtSplit(t.id, x[t.feature()])
Context and Attempts:
Other Steps Taken:
Environment Setup:
In case the graph above shows an error, run the following code (remove the # before the command "conda") conda install python-graphviz
So I created a conda environment and ran:
conda install -c conda-forge python-graphviz
Despite this, the error still occurs.
What I’ve Tried So Far:
Question:
I would appreciate any guidance or suggestions to resolve this error. Could this be related to a conflict between libraries or an issue with my environment setup?
Thanks in advance for any help!
this is the full error message:
TypeError Traceback (most recent call last)
Cell In[26], line 2
1 #%matplotlib inline
----> 2 viz = dtreeviz(modelo_iris,
3 X_train= x,
4 y_train= y,
5 target_name='Tipo_Orquidea',
6 feature_names=features,
7 class_names=['Não Orquídea', 'Orquídea'])
8 viz
File c:\Users\rocki\Miniconda3\lib\site-packages\dtreeviz\compatibility.py:254, in dtreeviz(tree_model, X_train, y_train, feature_names, target_name, class_names, tree_index, precision, orientation, instance_orientation, show_root_edge_labels, show_node_labels, show_just_path, fancy, histtype, highlight_path, X, max_X_features_LR, max_X_features_TD, depth_range_to_display, label_fontsize, ticks_fontsize, fontname, title, title_fontsize, colors, scale)
251 shadow_tree = ShadowDecTree.get_shadow_tree(tree_model, X_train, y_train, feature_names, target_name, class_names,
252 tree_index)
253 model = DTreeVizAPI(shadow_tree)
--> 254 return model.view(precision, orientation,
255 instance_orientation,
256 show_root_edge_labels, show_node_labels, show_just_path, fancy, histtype, highlight_path, X,
257 max_X_features_LR, max_X_features_TD, depth_range_to_display, label_fontsize, ticks_fontsize,
258 fontname, title, title_fontsize, colors=colors, scale=scale)
File c:\Users\rocki\Miniconda3\lib\site-packages\dtreeviz\trees.py:523, in DTreeVizAPI.view(self, precision, orientation, instance_orientation, show_root_edge_labels, show_node_labels, show_just_path, fancy, histtype, leaftype, highlight_path, x, max_X_features_LR, max_X_features_TD, depth_range_to_display, label_fontsize, ticks_fontsize, fontname, title, title_fontsize, colors, scale)
521 tmp = tempfile.gettempdir()
522 if x is not None:
...
--> 335 if self.shouldGoLeftAtSplit(t.id, x[t.feature()]):
336 return walk(t.left, x, path)
337 return walk(t.right, x, path)
TypeError: 'int' object is not subscriptable
Upvotes: 0
Views: 57