解決使用export_graphviz可視化樹報(bào)錯(cuò)的問題
在使用可視化樹的過程中,報(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è)參考,也希望大家多多支持腳本之家。
- vue報(bào)錯(cuò)之exports is not defined問題的解決
- 解決React報(bào)錯(cuò)Unexpected default export of anonymous function
- 關(guān)于JavaScript使用export和import的兩個(gè)報(bào)錯(cuò)解決
- 關(guān)于IDEA中的.VUE文件報(bào)錯(cuò) Export declarations are not supported by current JavaScript version
- 探索export導(dǎo)出一個(gè)字面量會(huì)報(bào)錯(cuò)export?default不會(huì)報(bào)錯(cuò)
相關(guān)文章
python檢測(cè)lvs real server狀態(tài)
這篇文章主要介紹了用python檢測(cè)lvs real server狀態(tài)的示例,大家參考使用吧2014-01-01python中sort和sorted排序的實(shí)例方法
在本篇文章中小編給大家?guī)淼氖顷P(guān)于python中sort和sorted排序的實(shí)例方法以及相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。2019-08-08python讀取nc數(shù)據(jù)并繪圖的方法實(shí)例
最近項(xiàng)目中需要處理和分析NC數(shù)據(jù),所以下面這篇文章主要給大家介紹了關(guān)于python讀取nc數(shù)據(jù)并繪圖的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05Django如何自定義model創(chuàng)建數(shù)據(jù)庫索引的順序
這篇文章主要介紹了Django如何自定義model創(chuàng)建數(shù)據(jù)庫索引的順序,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-06-06Python?isdigit()函數(shù)判斷字符串是否全都是數(shù)字字符示例
這篇文章主要為大家介紹了Python判斷字符串是否全都是數(shù)字字符示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01Python 內(nèi)置變量和函數(shù)的查看及說明介紹
今天小編就為大家分享一篇Python 內(nèi)置變量和函數(shù)的查看及說明介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12Django中模版的子目錄與include標(biāo)簽的使用方法
這篇文章主要介紹了Django中模版的子目錄與include標(biāo)簽的使用方法,有利于Python的Django框架的模版布局,需要的朋友可以參考下2015-07-07