0

I followed the the instructions in this thread to get my export working Python, PyDot and DecisionTree but a pdf export truncates the tree after a page width and the png is too small to read. Is there a way of creating a pdf with unlimited width?

My code is

from sklearn import tree

clf = tree.DecisionTreeClassifier().fit(X_train, y_train)


import pydotplus
from IPython.display import Image
from sklearn.externals.six import StringIO
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data,feature_names=cols_scaled.columns) 
graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) 
Image(graph.create_png())
graph.write_pdf("decisiontree.pdf")

Many thanks

jlt199
  • 2,349
  • 6
  • 23
  • 43

1 Answers1

0

Try using the following code, PDF requires width and let me know if it worked.

from sklearn.externals.six import StringIO
import pydotplus   #using pydotplus in windows10, python 3.6.X
dot_data = StringIO()

tree.export_graphviz(clf, out_file=dot_data, 
                         feature_names=cols_scaled.column,  
                         class_names=<replace target column here>,  
                         filled=True, rounded=True,  
                         special_characters=True)  
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
graph.write_pdf("iris.pdf")
ata
  • 3,398
  • 5
  • 20
  • 31
Linkon
  • 81
  • 10