我提出了一個樹分類命名的模型,並試圖用出口graphviz的功能是這樣的:樹分類到graphviz的錯誤
export_graphviz(decision_tree=model,
out_file='NT_model.dot',
feature_names=X_train.columns,
class_names=model.classes_,
leaves_parallel=True,
filled=True,
rotate=False,
rounded=True)
出於某種原因,我跑曾提出這樣的例外:
TypeError Traceback (most recent call last) <ipython-input-298-40fe56bb0c85> in <module>() 6 filled=True, 7 rotate=False, ----> 8 rounded=True) C:\Users\yonatanv\AppData\Local\Continuum\Anaconda3\lib\site- packages\sklearn\tree\export.py in export_graphviz(decision_tree, out_file, max_depth, feature_names, class_names, label, filled, leaves_parallel, impurity, node_ids, proportion, rotate, rounded, special_characters) 431 recurse(decision_tree, 0, criterion="impurity") 432 else: --> 433 recurse(decision_tree.tree_, 0, criterion=decision_tree.criterion) 434 435 # If required, draw leaf nodes at same depth as each other C:\Users\yonatanv\AppData\Local\Continuum\Anaconda3\lib\site- packages\sklearn\tree\export.py in recurse(tree, node_id, criterion, parent, depth) 319 out_file.write('%d [label=%s' 320 % (node_id, --> 321 node_to_str(tree, node_id, criterion))) 322 323 if filled: C:\Users\yonatanv\AppData\Local\Continuum\Anaconda3\lib\site- packages\sklearn\tree\export.py in node_to_str(tree, node_id, criterion) 289 np.argmax(value), 290 characters[2]) --> 291 node_string += class_name 292 293 # Clean up any trailing newlines TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U90') dtype('<U90') dtype('<U90')
我對可視化超參數是那些:
print(model)
DecisionTreeClassifier(class_weight={1.0: 10, 0.0: 1}, criterion='gini',
max_depth=7, max_features=None, max_leaf_nodes=None,
min_impurity_split=1e-07, min_samples_leaf=50,
min_samples_split=2, min_weight_fraction_leaf=0.0,
presort=False, random_state=0, splitter='best')
print(model.classes_)
[ 0. , 1. ]
幫助將不勝感激!
確保您使用的是scikit-learn的更新版本。如果仍然面臨這個問題,那麼你需要提供更多的細節來幫助我們。從錯誤的完整堆棧跟蹤開始。然後提供您用來訓練'model'的代碼以及一些樣本數據。 –
我正在使用安裝在anaconda3上的版本 –
爲我的問題添加了更多的處理,以便通知我! –