gpt4 book ai didi

python - 决策树显示没有达到我想要的效果

转载 作者:行者123 更新时间:2023-11-30 09:18:18 24 4
gpt4 key购买 nike

我正在尝试正确显示决策树;我非常接近,但我就是无法正确显示类(class)。

当我使用 class_names=True 时,我得到:

enter image description here

如何解释 class=y[1]?

这里有更多详细信息:

enter image description here

enter image description here

请注意,图像被剪裁,但它仍沿着相同的线条继续。

然后:

clf.fit(X, Y)
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=combo.columns[2:], class_names=class_names)
graph = graphviz.Source(dot_data)
graph.render('r')

它会产生这样的输出,我知道这是错误的,因为唯一出现 5 次的成绩是 A。

enter image description here

问题是什么?

相关链接

https://datascience.stackexchange.com/questions/28574/decisiontreeclassifier-object-has-no-attribute-importances这是一个有趣的答案,其中包含一些有用的提示,但根本没有回答我在这里提出的问题。

最佳答案

我找到了这个解决方案:

clf = tree.DecisionTreeClassifier(max_depth=4)
clf.fit(X, Y)
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=Xprep.columns, class_names=clf.classes_)

事实证明,在 fit 调用的结果上有一个稍微难以找到的属性:clf.classes_,其中包含类的文本再现。

关于python - 决策树显示没有达到我想要的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com