Python scikit learn tree.DecisionTreeClassifier导出为pdf太宽,无法容纳

Python scikit learn tree.DecisionTreeClassifier导出为pdf太宽,无法容纳,python,scikit-learn,Python,Scikit Learn,我按照此线程中的说明进行导出 但是pdf导出会在页面宽度过大后截断树,并且png太小,无法读取。有没有办法创建宽度不限的pdf 我的代码是 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

我按照此线程中的说明进行导出 但是pdf导出会在页面宽度过大后截断树,并且png太小,无法读取。有没有办法创建宽度不限的pdf

我的代码是

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")

非常感谢

尝试使用以下代码,PDF需要宽度,请告诉我是否有效

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")
从sklearn.externals.six导入StringIO
在windows10、python 3.6.X中使用pydotplus导入pydotplus#
dot_data=StringIO()
tree.export_graphviz(clf,out_file=dot_数据,
feature_names=cols_scaled.column,
类名称=,
填充=真,四舍五入=真,
特殊字符(为真)
graph=pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf(“iris.pdf”)

对于png,必须有一些参数来控制尺寸显示。我是否要使png不在控制台窗口中内联显示?我正在使用Windows10、Python3.5和Spyder