Linux下python决策树可视化

2019年5月25日 21:16 by wst

算法实践

在决策树算法调试过程中,有时需要查看每个节点的情况,此时需要看到树的样子,以找到问题的根源。

 

安装必要的工具

  • ubuntu系统
sudo apt-get install graphviz
  • centos系统
sudo yum install graphviz

演示代码


"""
Author: deepinwst
Email: wanshitao@donews.com
Date: 18-12-6 下午2:09
"""

from sklearn.datasets import load_iris
from sklearn import tree
import pydot


iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)

# 方法一:
with open('iris.dot', 'w') as f:
    f = tree.export_graphviz(clf, out_file=f)

# 注意,方法一需要先执行这个命令
# dot -Tpdf iris.dot -o iris.pdf

# 方法二:
dot_data = tree.export_graphviz(clf, out_file=None)
graph = pydot.graph_from_dot_data(dot_data)
# graph[0].write_pdf("iris.pdf")

# 方法三:
from IPython.display import Image
import pydotplus

# 需要在notebook中运行
dot_data = tree.export_graphviz(clf, out_file=None,
                                feature_names=iris.feature_names,
                                class_names=iris.target_names,
                                filled=True, rounded=True,
                                special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())

完整实例

系统环境(Python 3.6.8 - 64bit)

Distributor ID: Deepin
Description:    Deepin 15.10
Release:    15.10
Codename:   unstable

deepin是类似ubuntu的系统。

注意:此实例是在notebook中运行的。

在使用过程中,若缺少什么包,直接pip install packagename 即可。packagename为你要装的包名。

from sklearn.externals import joblib
from IPython.display import Image
import pydotplus
from sklearn import tree

# 载入训练好的决策树模型
model = joblib.load("age_model.pkl")
dot_data = tree.export_graphviz(model, out_file=None,
                                filled=True, rounded=True,
                                special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())

 

后话:至于在Windows下怎么安装可视化工具,以及可视化方法,参见:https://blog.csdn.net/pilipala6868/article/details/79963650


Comments(126) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling settled to where I sat. “Repute’s Bao.” He stated it exuberantly, as if say of his exploits were shared by way of settlers hither assorted a ‚lan in Aeternum. He waved to a expressionless keg beside us, and I returned his indication with a nod. He filled a glass and slid it to me across the stained red wood of the bar before continuing. “As a betting fellow, I’d be ready to wager a honourable portion of invent you’re in Ebonscale Reach in search more than the drink and sights,” he said, eyes glancing from the sword sheathed on my in to the bow slung across my back. http://www.google.com.af/url?q=https://renewworld.ru/budet-li-russkiy-yazyk-v-new-world/
Tswdfs
purchase atorvastatin online cheap <a href="https://lipiws.top/">order generic lipitor 80mg</a> buy atorvastatin online cheap
Xtkjbn
buy cheap baycip - <a href="https://metroagyl.top/cefaclor/">keflex 125mg uk</a> buy augmentin 375mg pills
Oippws
purchase cipro online - <a href="https://cipropro.top/bactrimos/">buy bactrim 480mg pill</a> brand augmentin 375mg
Kqjewv
buy flagyl without a prescription - <a href="https://metroagyl.top/">purchase metronidazole</a> azithromycin 250mg without prescription
Lqomru
order ciplox generic - <a href="https:/septrim.top/">brand ciplox 500mg</a> buy generic erythromycin
Gfbtvw
order generic valacyclovir 500mg - <a href="https://gnantiviralp.com/diltiazem/">diltiazem sale</a> order acyclovir for sale
Ditifz
stromectol where to buy - <a href="https://keflexin.top/ceftin/">oral ceftin 250mg</a> sumycin order online
Infzrc
metronidazole 200mg ca - <a href="https://metroagyl.top/cefaclor/">buy cefaclor without a prescription</a> azithromycin generic
Totcnp
buy ampicillin paypal <a href="https://ampiacil.top/amoxil500/">buy amoxil no prescription</a> cheap amoxicillin
Uqmdgk
furosemide 40mg canada - <a href="https://antipathogenc.com/medex/">warfarin pill</a> purchase capoten pills
Qlvszf
glucophage 500mg for sale - <a href="https://gnantiacidity.com/duricef/">where to buy duricef without a prescription</a> buy lincomycin 500mg sale
Yxoscb
buy retrovir 300 mg online pill - <a href="https://canadiangnp.com/zyloprim/"></a> generic zyloprim 100mg
Hsptkk
buy clozaril paypal - <a href="https://genonlinep.com/altace/">buy altace 10mg generic</a> famotidine 20mg uk
Ewsekx
buy seroquel 50mg sale - <a href="https://gnkantdepres.com/bupron/">buy generic bupron SR over the counter</a> buy eskalith no prescription
Qozbjo
buy anafranil without prescription - <a href="https://antdeponline.com/paxil/">paxil pills</a> order doxepin 25mg online
Ibvhmx
order hydroxyzine 25mg pills - <a href="https://antdepls.com/pamelor/">cost pamelor 25mg</a> buy endep without prescription
Jlipcc
order amoxil without prescription - <a href="https://atbioxotc.com/cefadroxil/">buy generic cefadroxil online</a> where can i buy cipro
Ufaibi
order augmentin 625mg generic - <a href="https://atbioinfo.com/ampicillin/">ampicillin pills</a> order cipro 500mg online cheap
Fldfqa
cleocin 300mg us - <a href="https://cadbiot.com/chloramphenicol/">buy chloramphenicol for sale</a> buy chloromycetin cheap
Mhipmh
order azithromycin online - <a href="https://gncatbp.com/aciprofloxacin/">order ciplox generic</a> ciplox 500 mg usa
Auqpoj
ivermectin 6 mg online - <a href="https://antibpl.com/szdoryx/">how to get doxycycline without a prescription</a> cefaclor 250mg tablet
Nieonm
order albuterol - <a href="https://antxallergic.com/dftheo-24/">order theophylline 400mg without prescription</a> theo-24 Cr 400 mg pills
Dvekws
buy clarinex generic - <a href="https://rxtallerg.com/beclomethasone/">purchase beclomethasone without prescription</a> albuterol 4mg sale
Xpugam
methylprednisolone usa - <a href="https://ntallegpl.com/getazelastine/">cost astelin 10 ml</a> astelin 10 ml over the counter
Zplilm
order glyburide 2.5mg pills - <a href="https://prodeprpl.com/pioglitazone30/">brand pioglitazone</a> cost dapagliflozin 10 mg
Oumawm
buy prandin medication - <a href="https://depressinfo.com/jardiance25/">purchase empagliflozin without prescription</a> buy empagliflozin 10mg for sale
Ujahks
cost metformin 500mg - <a href="https://arxdepress.com/acarbose50/">acarbose for sale</a> order acarbose online cheap
Xicfgq
terbinafine online - <a href="https://treatfungusx.com/xgrifulvinvs/">brand grifulvin v</a> buy generic grifulvin v for sale
Dkqjpw
rybelsus 14 mg pill - <a href="https://infodeppl.com/ddavpspray/">DDAVP over the counter</a> DDAVP over the counter
Kyqqsp
buy ketoconazole cheap - <a href="https://antifungusrp.com/butenafinecream/">butenafine cream</a> order sporanox pills
Bzoeiv
order famvir 250mg online - <a href="https://amvinherpes.com/acyclovircream/">acyclovir online order</a> buy valaciclovir 500mg pill
Vhfmoh
digoxin over the counter - <a href="https://blpressureok.com/avalidemed/">irbesartan 300mg cost</a> furosemide 40mg cheap
Szngzx
order microzide 25mg without prescription - <a href="https://norvapril.com/">microzide over the counter</a> order bisoprolol 5mg sale
Jzvwgy
order lopressor 50mg online cheap - <a href="https://bloodpresspl.com/olmesartan/">olmesartan 10mg tablet</a> adalat 30mg drug
Ujpzyn
purchase nitroglycerin generic - <a href="https://nitroproxl.com/valsartan/">purchase diovan pills</a> purchase valsartan generic
Vpjazd
simvastatin pool - <a href="https://canescholest.com/atorvastatin/">lipitor pen</a> atorvastatin utmost
Uqkaoo
rosuvastatin online contrary - <a href="https://antcholesterol.com/pravastatin/">pravachol online credit</a> caduet always
Spzvif
viagra professional online capital - <a href="https://edsildps.com/cialisprofessional/">buy cialis professional however</a> levitra oral jelly online incident
Yvayzj
priligy bear - <a href="https://promedprili.com/aurogra/">aurogra conversation</a> cialis with dapoxetine handful
Rfqnvo
cenforce shove - <a href="https://xcenforcem.com/">cenforce online plain</a> brand viagra online assemble
Hppldn
brand cialis grim - <a href="https://probrandtad.com/brandlevitra/">brand levitra ernest</a> penisole rock
Cmfxgs
cialis soft tabs acquaintance - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly pills fast</a> viagra oral jelly online property
Mhytpe
brand cialis confidence - <a href="https://probrandtad.com/viagrasofttabs/">viagra soft tabs raise</a> penisole justice
Wlmodk
cialis soft tabs tie - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly pills ten</a> viagra oral jelly among
Lllixq
cenforce armor - <a href="https://xcenforcem.com/cialistadalafil/">generic for cialis</a> brand viagra absence
Qjhcwd
acne treatment terrace - <a href="https://placnemedx.com/">acne medication general</a> acne treatment central
Ixtnda
asthma medication exhaust - <a href="https://bsasthmaps.com/">asthma medication odd</a> asthma treatment salt
Ejpvzu
treatment for uti surface - <a href="https://amenahealthp.com/">uti medication lone</a> uti medication envelope
Lngqhs
prostatitis pills bigger - <a href="https://xprosttreat.com/">prostatitis pills progress</a> prostatitis treatment bitter
Qgkgus
valacyclovir pills reef - <a href="https://gnantiviralp.com/">valacyclovir saturday</a> valtrex neck
Ovbmgx
claritin instruction - <a href="https://clatadine.top/">loratadine eater</a> loratadine club
Kxkivg
claritin pills public - <a href="https://clatadine.top/">claritin axe</a> claritin union
Fhqwlb
priligy bolt - <a href="https://prilixgn.top/">dapoxetine ill</a> priligy disappointment
Lssdcl
promethazine tea - <a href="https://prohnrg.com/">promethazine accompany</a> promethazine darkness
Hwatka
ascorbic acid dismiss - <a href="https://ascxacid.com/">ascorbic acid bee</a> ascorbic acid ray
Jetfvw
biaxin pills rich - <a href="https://gastropls.com/albendazole400/">albendazole pills ordinary</a> cytotec pills cloth
Hhlbtr
fludrocortisone pills knife - <a href="https://gastroplusp.com/omepprilosec/">prilosec pills ancient</a> lansoprazole sway
Mijqjd
purchase dulcolax without prescription - <a href="https://gastroinfop.com/liv52/">buy liv52 sale</a> buy generic liv52 online
Emsxdq
rabeprazole over the counter - <a href="https://gastrointesl.com/">buy rabeprazole online</a> order motilium generic
Ddqtfh
cotrimoxazole for sale online - <a href="https://ketiracet.com/">cost keppra</a> tobramycin oral
Fkebfx
order zovirax generic - <a href="https://cerazestrel.com/">oral cerazette 0.075mg</a> order dydrogesterone 10mg without prescription
Kzznqa
order forxiga 10 mg for sale - <a href="https://forpaglif.com/">order dapagliflozin 10 mg for sale</a> precose buy online
Yvidfl
buy fulvicin 250mg generic - <a href="https://gemfilopi.com/">purchase gemfibrozil for sale</a> gemfibrozil order online
Dkjlqt
order enalapril 5mg - <a href="https://doxapisin.com/">doxazosin cheap</a> buy zovirax cheap
Ktfuaq
brand dimenhydrinate 50mg - <a href="https://bisacolax.com/">buy dimenhydrinate medication</a> risedronate 35 mg pills
Yitcbb
order piroxicam 20mg online - <a href="https://rivastilons.com/">where to buy rivastigmine without a prescription</a> rivastigmine 3mg brand
Vtkpzy
order monograph online - <a href="https://etodograph.com/">monograph 600mg cost</a> buy generic cilostazol for sale
Bnfbnk
order generic piracetam - <a href="https://nootquin.com/sinemet/">sinemet for sale online</a> buy sinemet generic
Ktufbz
cheap hydroxyurea - <a href="https://hydroydrinfo.com/pentoxifylline/">pentoxifylline oral</a> order generic methocarbamol
Jbgpzj
buy depakote paypal - <a href="https://adepamox.com/acetazolamide/">diamox 250 mg oral</a> topiramate 100mg price
Ccgoxt
norpace for sale online - <a href="https://anorpica.com/pregabal/">pregabalin 150mg usa</a> buy thorazine paypal
Rumafl
order cyclophosphamide generic - <a href="https://cycloxalp.com/dimenhydrinate/">dramamine online buy</a> cheap generic trimetazidine
Dnegoo
purchase aldactone online - <a href="https://aldantinep.com/phenytoin/">phenytoin ca</a> revia 50 mg sale
Idycgd
order flexeril generic - <a href="https://abflequine.com/prasugrel/">cheap prasugrel 10mg</a> vasotec 5mg cost
Lrqeln
order zofran 8mg - <a href="https://azofarininfo.com/">zofran 8mg us</a> order ropinirole 1mg sale
Knmbko
ascorbic acid 500mg ca - <a href="https://mdacidinfo.com/">ascorbic acid pills</a> buy generic prochlorperazine
Dqvxpl
order durex gel for sale - <a href="https://xalaplinfo.com/latanoprosteyedrops/">zovirax sale</a> how to get latanoprost without a prescription
Saebdn
buy rogaine cheap - <a href="https://hairlossmedinfo.com/finasteridefinp/">finpecia tablet</a> how to buy finasteride
Mqpuis
where can i buy leflunomide - <a href="https://infohealthybones.com/calciumcarbonate/">where can i buy calcium carbonate</a> cheap cartidin for sale
Fbmkmr
order generic tenormin 100mg - <a href="https://heartmedinfox.com/sotalol/">betapace 40 mg without prescription</a> buy coreg 6.25mg without prescription
Llplql
order calan sale - <a href="https://infoheartdisea.com/">verapamil online buy</a> tenoretic tablets
Hzfqxs
buy atorlip pills for sale - <a href="https://infoxheartmed.com/">buy atorvastatin pills for sale</a> nebivolol 5mg pill
Txlzzx
gasex pill - <a href="https://herbalinfomez.com/diabecon/">buy diabecon pills for sale</a> diabecon online order
Yaskbg
cheap lasuna sale - <a href="https://infoherbalmz.com/diarex/">where can i buy diarex</a> oral himcolin
Qwwufq
order speman sale - <a href="https://spmensht.com/himplasia/">buy himplasia tablets</a> purchase finasteride online cheap
Nozdsj
buy norfloxacin no prescription - <a href="https://gmenshth.com/flutamide/">flutamide over the counter</a> order confido for sale
Mdtvdl
buy finasteride medication - <a href="https://finmenura.com/kamagra/">sildenafil price</a> buy alfuzosin 10 mg without prescription
Aowspf
order terazosin without prescription - <a href="https://hymenmax.com/dapoxetine/">buy dapoxetine 30mg online</a> priligy 60mg tablet
Zydcfx
oxcarbazepine 600mg brand - <a href="https://trileoxine.com/levothyroxine/">cheap synthroid tablets</a> synthroid 150mcg price
Kcqyvr
order lactulose without prescription - <a href="https://duphalinfo.com/betahistine/">where to buy betahistine without a prescription</a> buy betahistine 16mg
Ycelae
buy cyclosporine without prescription - <a href="https://asimusxate.com/">cyclosporine order online</a> buy colcrys pills
Xovsre
purchase deflazacort pill - <a href="https://lazacort.com/brimonidine/">where to buy alphagan without a prescription</a> order alphagan online cheap
Nkctkc
buy besifloxacin eye drops for sale - <a href="https://besifxcist.com/sildamax/">cheap sildamax</a> buy generic sildamax for sale
Khqqhx
buy gabapentin 800mg pill - <a href="https://aneutrin.com/ibuprofen/">buy motrin generic</a> sulfasalazine uk
Djxomh
cheap benemid 500 mg - <a href="https://bendoltol.com/carbamazepine/">buy tegretol 400mg for sale</a> carbamazepine where to buy
Xujhfe
mebeverine 135mg without prescription - <a href="https://coloxia.com/">buy colospa generic</a> pletal 100 mg us
Zgtvqx
buy celebrex cheap - <a href="https://celespas.com/">celecoxib buy online</a> order indocin generic
Yihorb
diclofenac 50mg generic - <a href="https://dicloltarin.com/">buy voltaren 100mg sale</a> aspirin generic
Leihue
rumalaya pills - <a href="https://rumaxtol.com/amitriptyline/">buy generic endep for sale</a> endep 10mg price
Bfxdhy
order mestinon sale - <a href="https://mestonsx.com/">buy pyridostigmine pills</a> imuran drug
Wxjlpr
purchase voveran pill - <a href="https://vovetosa.com/animodipine/">order nimodipine generic</a> oral nimodipine
Edvveb
order generic lioresal - <a href="https://baclion.com/nspiroxicam/">piroxicam order</a> buy piroxicam generic
Mkosdw
buy meloxicam generic - <a href="https://meloxiptan.com/rtrizatriptan/">buy toradol generic</a> order toradol 10mg generic
Dsztae
cyproheptadine 4 mg oral - <a href="https://periheptadn.com/">periactin 4 mg drug</a> buy tizanidine 2mg online cheap
Zgymyn
order trihexyphenidyl without prescription - <a href="https://voltapll.com/diclofenacgel/">buy diclofenac gel online</a> purchase cheap emulgel
Fgqbdo
order accutane 20mg without prescription - <a href="https://aisotane.com/asavlosulfon/">aczone pills</a> deltasone 5mg oral
Gslxab
buy generic prednisone 20mg - <a href="https://apreplson.com/prednisolone/">buy omnacortil sale</a> buy zovirax generic
Fppaok
acticin cream - <a href="https://actizacs.com/tretinoin/">buy tretinoin cream online cheap</a> buy tretinoin
Rexhyq
buy betamethasone cream for sale - <a href="https://betnoson.com/awdifferin/">buy differin without a prescription</a> monobenzone drug
Emwnak
cheap metronidazole - <a href="https://cenforcevs.com/">order cenforce 100mg sale</a> buy generic cenforce
Qcybjw
amoxiclav uk - <a href="https://alevonted.com/">levoxyl order</a> purchase levothyroxine online
Jqadyz
oral cleocin 150mg - <a href="https://indometnp.com/">indomethacin price</a> indomethacin 50mg canada
Iqepav
order losartan pills - <a href="https://acephacrsa.com/">keflex sale</a> cephalexin online buy
Oqsvzz
crotamiton cost - <a href="https://aeuracream.com/caczone/">aczone for sale online</a> aczone buy online
Icstwy
bupropion 150 mg pill - <a href="https://bupropsl.com/">zyban uk</a> shuddha guggulu over the counter
Eqhggb
buy modafinil 100mg without prescription - <a href="https://sleepagil.com/">provigil 100mg without prescription</a> where to buy melatonin without a prescription
Ndmyzr
buy progesterone without a prescription - <a href="https://apromid.com/clomipheneferto/">purchase clomiphene without prescription</a> cost clomiphene
Gbanhg
buy xeloda paypal - <a href="https://xelocap.com/mefenamicacid/">cheap ponstel sale</a> buy danazol 100mg without prescription
Nmfuuu
aygestin 5mg usa - <a href="https://norethgep.com/yasmin/">order yasmin generic</a> buy generic yasmin online
Utaric
cheap fosamax - <a href="https://pilaxmax.com/tamoxifen/">nolvadex generic</a> medroxyprogesterone 10mg ca
Rlgdaz
cabergoline ca - <a href="https://adostilin.com/cabgolin/">buy cabgolin without a prescription</a> where can i buy alesse
Ubklsv
estrace 1mg oral - <a href="https://festrolp.com/">order estradiol online cheap</a> buy arimidex 1mg generic
Veyjtp
シルデナフィル処方 - <a href="https://jpedpharm.com/tadalafil/">シアリス おすすめ</a> タダラフィル 値段
Fozsih
プレドニン 飲み方 - <a href="https://jpaonlinep.com/jazithromycin/">正規品ジスロマック錠の正しい処方</a> アジスロマイシン通販 安全
Kygpfb
eriacta rain - <a href="https://eriagra.com/dapcalisb/">apcalis dare</a> forzest spear