您好,登錄后才能下訂單哦!
在使用可視化樹的過程中,報(bào)錯(cuò)了。說是‘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');
報(bào)錯(cuò)信息:
解決方法:
先使用安裝pydot:
pip install pydot
然后再下載Graphviz(http://www.graphviz.org 選擇msi版本)一路安裝,記住默認(rèn)的安裝路徑
c:\Program Files (x86)\Graphviz2.38\。
將Graphviz2.38添加到環(huán)境變量中
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可視化樹報(bào)錯(cuò)的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。