您好,登錄后才能下訂單哦!
在使用可視化樹的過程中,報錯了。說是‘dot.exe'not found in path
原代碼:
# import tools needed for visualization from sklearn.tree import export_graphviz import pydot #Pull out one tree from the forest tree = rf.estimators_[5] # Export the image to a dot file export_graphviz(tree, out_file = 'tree.dot', feature_names = features_list, rounded = True, precision = 1) #Use dot file to create a graph (graph, ) = pydot.graph_from_dot_file('tree.dot') # Write graph to a png file graph.write_png('tree.png');
報錯信息:
解決方法:
先使用安裝pydot:
pip install pydot
然后再下載Graphviz(http://www.graphviz.org 選擇msi版本)一路安裝,記住默認的安裝路徑
c:\Program Files (x86)\Graphviz2.38\。
將Graphviz2.38添加到環境變量中
import os os.environ['PATH'] = os.environ['PATH'] + (';c:\\Program Files (x86)\\Graphviz2.38\\bin\\')
之后便可以正常使用了。
修改后代碼:
# import tools needed for visualization from sklearn.tree import export_graphviz import pydot import os os.environ['PATH'] = os.environ['PATH'] + (';c:\\Program Files (x86)\\Graphviz2.38\\bin\\') #Pull out one tree from the forest tree = rf.estimators_[5] # Export the image to a dot file export_graphviz(tree, out_file = 'tree.dot', feature_names = features_list, rounded = True, precision = 1) #Use dot file to create a graph (graph, ) = pydot.graph_from_dot_file('tree.dot') # Write graph to a png file graph.write_png('tree.png');
以上這篇解決使用export_graphviz可視化樹報錯的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。