export_text上的错误
我正在尝试使用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_)
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来像是export_text代码中的一个小错误。尝试强迫
feature_names_in _
成为python列表。我假设您使用
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.I assume you used a
pandas.DataFrame
when generating the DecisionTree so that you get thefeature_names_in_
?If that's the case then
feature_names_in_
will be anumpy.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 forplot_tree