決定木を描画するために以下のコードを実行。
# indexの抽出
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)
#決定木を描画
viz = dtreeviz(
clf,
data_e,
data_o,
target_name='Class',
feature_names=time_index,
class_names=['False','True'],
)
viz
以下のTypeError が出ます。
C:\Users\ichir\AppData\Local\Temp\ipykernel_10292\1620574054.py:10: DeprecationWarning: dtreeviz() function is deprecated starting from version 2.0.
For the same functionality, please use this code instead:
m = dtreeviz.model(...)
m.view()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[35], line 10
7 print(time_index)
9 # 決定木を描画
---> 10 viz = dtreeviz(
11 clf,
12 data_e,
13 data_o,
14 target_name='Class',
15 feature_names=time_index,
16 class_names=['False','True']
17 )
18 viz
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 = adjust_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
以下各変数になります。
x_0.head(5)
日時
2018-11-30
2018-12-31
2019-01-31
2019-02-28
2019-03-31
df_info.head(5)
顧客ID 宿泊者名 プラン 金額
日時
2018-11-01 00:02:21 110034 若松 花子 B 19000
2018-11-01 00:03:10 112804 津田 美加子 D 20000
2018-11-01 00:06:19 110275 吉本 美加子 D 20000
2018-11-01 00:08:41 110169 坂本 直人 B 19000
2018-11-01 00:12:22 111504 青山 零 A 15000
よろしくお願いします。