【发布时间】:2020-01-02 19:33:08
【问题描述】:
我正在尝试根据我在 DataCamp 上找到的文章绘制我的决策树:https://www.datacamp.com/community/tutorials/decision-tree-classification-python。但是,我收到一个属性错误:
from sklearn.tree import export_graphviz
from sklearn.externals.six import StringIO
from IPython.display import Image
import pydotplus
decision_tree = DecisionTreeRegressor(max_depth=3)
decision_tree.fit(train_features, train_targets)
# Predict values for train and test
train_predictions = decision_tree.predict(train_features)
test_predictions = decision_tree.predict(test_features)
dot_data = StringIO()
export_graphviz(decision_tree, out_file=dot_data, filled=True, rounded=True, special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png('decision_tree.png')
Image(graph.create_png())
AttributeError: module 'pydotplus' has no attribute 'Node'
有没有人知道我应该去哪里调查?
【问题讨论】:
-
与错误相关的行是什么?
-
它指的是pydotplus包:~\AppData\Local\Programs\Python\Python36\lib\site-packages\pydotplus\parser.py in push_node_stmt(s, loc, toks) 374 node_name = node_name[0] 375 --> 376 n = pydotplus.Node(str(node_name), **attrs) 377 return n 378
-
在 10 11 export_graphviz(decision_tree, out_file=dot_data, special_characters=True) ---> 12 graph = pydotplus.graph_from_dot_data(dot_data.getvalue( )) 13 graph.write_png('decision_tree.png') 14 Image(graph.create_png())
标签: python plot decision-tree