Error in drawing decision tree

Asked 1 years ago, Updated 1 years ago, 448 views

Execute the following code to draw the decision tree.

#index extraction
x_0 = df_info.resample('M') .count()
x_0=x_0.drop(x_0.columns.values,axis=1)
time_index=x_0.index
print(time_index)

# Draw decision tree
viz = dtreeviz(
    clf,
    data_e, 
    data_o,
    target_name = 'Class',
    feature_names = time_index,
    class_names = ['False', 'True' ],
) 
viz

The following TypeError will appear:

 C:\Users\ichir\AppData\Local\Temp\ipykernel_10292\1620574054.py:10: DeprecationWarning: dtreeviz() function is decremented starting from version 2.0. 
 For the same functionality, please use this code installed: 
 m=dtreeviz.model(...) 
 m.view()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [35], line 10
      7 print(time_index)
      9#Draw Decision Tree
--- > 10 viz = dtreeviz(
     11clf,
     12 data_e, 
     13 data_o,
     14 target_name = 'Class',
     15 feature_names = time_index,
     16 class_names = ['False', 'True' ]
     17 ) 
     18viz

File ~\anaconda3\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, scale)

File ~\anaconda3\lib\site-packages\dtreeviz\trees.py:454, 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)
    451 return self.shadow_tree.leaves
    453 n_classes=self.shadow_tree.nclasses()
-->454 colors=just_colors(colors, n_classes)
    456 if orientation=="TD":
    457 ranksep=".2"

File~\anaconda3\lib\site-packages\dtreeviz\colors.py:119, in adjust_colors (colors, n_classes, cmp)
    116 COLORS["classes"] = get_hex_colors(n_classes,cmp)
    117 return COLORS
-->119 return dict (COLORS, **colors)

TypeError: dict() argument after ** must be a mapping, not float

The variables are as follows:

x_0.head(5)

date and time
2018-11-30
2018-12-31
2019-01-31
2019-02-28
2019-03-31


df_info.head(5)
    Customer ID Guest Name Plan Amount
date and time              
2018-11-0100:02:21 110034 Hanako Wakamatsu B 19000
2018-11-0100:03:10 112804 Mikako Tsuda D20000
2018-11-0100:06:19110275 Mikako Yoshimoto D20000
2018-11-0100:08:4110169 Naoto Sakamoto B19000
2018-11-0100:12:22111504 Aoyama Zero A15000

Thank you for your cooperation.

python python3

2023-01-31 07:38

1 Answers

As with the previous question, dtreeviz revision may have changed the specification.

For example, the programs in these articles work as they are until the 1.4.1 version, but after the 2.0.0 version, errors similar to the previous and this question occur.
Install dtreeviz to visualize the decision tree [Python]
Python library (visible decision tree)conversion):dtreeviz

Why don't you check the changed specifications and modify the program to fit them, or specify the number of versions that work when you install dtreeviz as follows?
Sample Jupiter Installation on Cells:

!pip install-Udtreeviz==1.4.1

The information about what happened after 2.0.0 seems to be included in the information at the time of release below.
Releases/2.0.0

If we were to modify the program to accommodate the latest version, wouldn't it be as follows?

import should be:

import dtreeviz

The method call is actually at the beginning of the error message.is as follows:

viz=dtreeviz.model(#### omitted below)


2023-01-31 09:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.