from sklearn import tree
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
import pydotplus
from IPython.display import Image
wine = load_wine()
Xtrain,Xtest,Ytrain,Ytest = train_test_split(wine.data,wine.target,test_size=0.3)
clf = tree.DecisionTreeClassifier(criterion='entropy')
clf = clf.fit(Xtrain,Ytrain)
score = clf.score(Xtest,Ytest)
print(score)
feature_name = ['酒精','苹果酸','灰','灰的碱性','镁','总酚','类黄酮','非黄烷类酚类','花青素','颜色强度','琴酒','雪莉','贝尔摩德']
dot_data = tree.export_graphviz(clf
,out_file=None
,feature_names= feature_name
,class_names=['琴酒','雪莉','贝尔摩德']
,filled = True
解决sklearn中,Graphviz画决策树中文乱码的问题
最新推荐文章于 2024-04-04 15:17:19 发布
通过修改sklearn ree_export.py文件,将字体替换为'宋体'或'微软雅黑',并添加rounded=True及special_characters=True,可以解决使用Graphviz绘制决策树时的中文乱码问题。
摘要由CSDN通过智能技术生成