export_text上的错误

发布于 2025-01-27 10:06:03 字数 792 浏览 3 评论 0原文

我正在尝试使用sklearn.tree(版本1.0.2)的function export_text,但是当我使用parameter feature_names时,我会遇到错误,这就是我正在尝试的

# decision_tree is the fitted algorithm
text_representation = export_text(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_)

如果我在没有功能的情况下调用该函数,则已经检查了,我已经检查了,并且deciple_tree.feature_names_in _返回正确的名称,

与我用作 算法的输入相同具有相同参数的其他类似功能,对

plot_tree(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_)

可能出错的情况有什么好处?

I'm trying to use the function export_text from sklearn.tree (version 1.0.2), but when I'm using the parameter feature_names I get an error, this is what I'm trying

# decision_tree is the fitted algorithm
text_representation = export_text(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_)

enter image description here

If I call the function without the feature_names parameter it works, I already checked and the decision_tree.feature_names_in_ returns the right names, the same I used as input for the algorithm

If I use this other similar function with the same arguments, it works fine

plot_tree(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_)

any idea of what could it be wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2025-02-03 10:06:03

它看起来像是export_text代码中的一个小错误。尝试强迫feature_names_in _成为python列表。

# decision_tree is the fitted algorithm
text_representation = export_text(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_.tolist())

我假设您使用pandas.dataframe在生成决策流时,您可以获得feature_names_in _

如果是这种情况,则feature_names_in _将是numpy.ndarray

export_text代码执行一个简单:如果功能_names:测试要检查功能,但是Numpy会增加您看到的错误。

看起来它是特定于export_text的,因此您看不到plot_tree

It looks like a small bug in the export_text code. Try forcing features_names_in_ to be a python list.

# decision_tree is the fitted algorithm
text_representation = export_text(decision_tree=decision_tree, feature_names=decision_tree.feature_names_in_.tolist())

I assume you used a pandas.DataFrame when generating the DecisionTree so that you get the feature_names_in_?

If that's the case then feature_names_in_ will be a numpy.ndarray.

The export_text code does a simple: if feature_names: test to check for features, but numpy will raise the error you see.

This looks like it's specific to the export_text, so you don't see it for plot_tree

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文