2016-09-02 5 views
0

Ich versuche, einen Entscheidungsbaum in Python zu bauen und zu visualisieren. Graphviz erzeugt jedoch ein Problem. HierEntscheidungsbaum Visualisierung

ist der Code, den ich versuchte:

# -*- coding: utf-8 -*- 
import pandas as pd 
from pandas import Series, DataFrame 
import numpy as np 
import os 
import matplotlib.pylab as plt 
import sklearn 
from sklearn.cross_validation import train_test_split 
from sklearn.tree import DecisionTreeClassifier 
import sklearn.metrics 
from sklearn.metrics import classification_report 
from sklearn import tree 
from io import BytesIO as StringIO 
from IPython.display import Image 
import pydot 
import pydotplus 
import graphviz 

path = "C:\\Users\\admin\\PycharmProjects\\conference\\New\\decision_tree\\" 

data = pd.read_csv(path + "weights.csv") 
data_clean = data.dropna() 

#data_clean.dtypes() 
#data_clean.describe() 

predictors = data_clean[['anxiety', 'taking']] 
target = data_clean['influence_score'] 

pred_train, pred_test, tar_train, tar_test = train_test_split(predictors,target, test_size=.2) 

#pred_train.shape 
#pred_test.shape 
#tar_test.shape 
#tar_train.shape 

classifier = DecisionTreeClassifier() 
classifier = classifier.fit(pred_train,tar_train) 

predictons = classifier.predict(pred_test) 

sklearn.metrics.confusion_matrix(tar_test,predictons) 

data = StringIO() 

#out_dot = path + "tree.dot" 
tree.export_graphviz(classifier, out_file = data) 

graph = pydotplus.graph_from_dot_data(data.getvalue()) 

out_tree = path + "tree_full.pdf" 

graph.write_pdf(out_tree) 

Jedoch habe ich diesen Fehler erhalte.

File "C:\Python27\lib\site-packages\pydotplus\graphviz.py", line 1960, in create 
    'GraphViz\'s executables not found') 
pydotplus.graphviz.InvocationException: GraphViz's executables not found 

folge ich habe die ganze Prozedur für Graphviz und pydotplus Installation der Umgebungsvariablen einschließlich der Änderung und auch sie in Python IDE importieren (I PyCharm verwenden). Graphviz-Version installiert 2.38.

Wie mache ich das funktioniert.

+1

Mögliches Duplikat von [Wie man einen Baum mit graphviz graphisch darstellt?] (Http://stackoverflow.com/questions/39146728/how-to-graph-a-tree-with-graphviz) –

+0

in dieser Frage hatte das Plakat graphviz nicht separat installiert, was das Problem verursacht hat. Ich habe es separat installiert, aber ich bekomme immer noch diesen Fehler –

Antwort

0

Ich löste es. Es scheint, dass ich beim Aktualisieren der Umgebungsvariablen einen Fehler gemacht habe. funktioniert gut.