一个空块总是出现在我的决策树上,由python创建
就像图片中的情况一样,我的决策树总是有一个空的块。 我已经搜索了一段时间,但仍然找不到解决方案。 我的代码在下面列出,在jupyter笔记本中运行。 希望您的帮助。
from sklearn import tree
from sklearn import datasets
import pydotplus
wine = datasets.load_wine()
X = wine.data
Y = wine.target
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.3)
clf = tree.DecisionTreeClassifier(criterion = 'gini').fit(X_train,Y_train)
clf.score(X_train,Y_train)
clf.predict(X_test)
feature_names = wine.feature_names
target_name = wine.target_names
import graphviz
dot_data = tree.export_graphviz(clf,
out_file = None,
feature_names = feature_na,
class_names = target_name,
filled = None,
rounded = True,)
dot_data = dot_data.replace('helvetica', 'Microsoft JhengHei')
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_pdf('wine.pdf')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的包裹经理很有可能搞砸了。您是否使用PIP安装软件包?尝试通过conda安装(我建议创建)。
另外,我认为您在第24行中有一个错别字:feature_names = feature_na(mes)。通过通过conda +修复错字并运行代码的软件包,我得到了以下树。
I think there is a very high chance that your package manager messed up. Have you used pip to install the packages? Try installing via conda (I recommend creating conda virtual environment).
Also I think you have a typo at line 24: feature_names = feature_na(mes). By installing packages via conda + fixing the typo and running your code I got the following tree.