首先我也去找过网络上的很多文章,也提出了很多方法供我解决问题,但是最终试了很多都不行,比如去修改“C:\Program Files (x86)\Graphviz2.38\fonts\fonts.cont”文件中的某些代码,但是我电脑打开看的时候已经是修改过的(可能是我之前有过修改),还是不能解决掉问题,结果出来还是如下图所示。
from math import log
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn import tree
import graphviz
import pydotplus
#建立模型
ent_tree= tree.DecisionTreeClassifier(criterion="entropy",
min_samples_split=2,
max_depth=5,
min_impurity_decrease=0.0)
#训练模型
ent_tree.fit(Xtrain,Ytrain)
#生成dot文件
dot_tree= tree.export_graphviz(ent_tree, out_file=None,
feature_names=X.columns,
class_names=['否', '是'],

博客内容讲述了在使用Python的sklearn库和graphviz进行决策树可视化时遇到的中文乱码问题。作者尝试了修改配置文件等方法无效,最后通过将dot文件中的'helvetica'字体替换为'MicrosoftYaHei'成功解决了中文显示问题。

538

被折叠的 条评论
为什么被折叠?



