从XGBClassifier产生的决策树中检索值
我使用类 xgbClassifier 来构建我的模型,然后在树上看到它,如下所示:
(...)
best_model = XGBClassifier(use_label_encoder=False,
eval_metric = 'logloss',
learning_rate = 1,
max_depth = 3,
n_estimators = 200)
(...)
from xgboost import plot_tree
import matplotlib.pyplot as plt
plot_tree(best_model,num_trees=0,rankdir='LR')
当然,它绘制了由我的分类器计算的最佳决策树。 我的问题是:如何检索图表叶子印刷的值?我相信它们存储在 best_model 中,但我不知道要使用哪种方法来获取这些值。
谢谢你!
I used the class XGBClassifier to build my model and then I visualized it in a tree as follows:
(...)
best_model = XGBClassifier(use_label_encoder=False,
eval_metric = 'logloss',
learning_rate = 1,
max_depth = 3,
n_estimators = 200)
(...)
from xgboost import plot_tree
import matplotlib.pyplot as plt
plot_tree(best_model,num_trees=0,rankdir='LR')
Which, of course, plotted the best decision tree calculated by my classifier.
My question is: how can I retrieve the values that are printed in leaves of my diagram? I believe they are stored in best_model but I don't know which method to use to get these values.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Python 中,您可以将值转储到如下字符串:
或文件:
或数据帧:
In Python you can dump the values to a string like this:
or to a file:
or to a dataframe: