问题描述
我已经解决了以下问题:
I have gone through the below questions:
如何提取 GradientBosstingClassifier 的决策规则
如何从中提取决策规则scikit-learn 决策树?
但是以上两个并没有解决我的目的.以下是我的查询:
However the above two does not solve my purpose. Below is my query:
我需要使用 gradientboostingclassifer 在 Python 中构建一个模型,并在 SAS 平台中实现这个模型.为此,我需要从 gradientboostingclassifer 中提取决策规则.
I need to build a model in Python using gradientboostingclassifer and implement this model in SAS platform. To do this I need to extract decision rules from the gradientboostingclassifer .
以下是我目前尝试过的:
Below is what I have tried so far:
在 IRIS 数据上构建模型:
Build the model on the IRIS data:
绘制图表后,我检查了第一棵树的图表源代码,并使用以下代码写入文本文件:
After the plotting of the graph, I have checked the source code of the graph for the 1st tree and write to text file using the below code:
以下是输出文件:
为了从输出文件中提取决策规则,我尝试了以下 python RegEX 代码来转换为 SAS 代码:
To extract the decision rules from the output file I have tried the below python RegEX code to translate to SAS code:
以下是上述代码的输出 SAS:
below is the output SAS from the above code:
如您所见,输出文件中缺少一块,即我无法正确打开/关闭 do-end 块.为此,我需要使用节点号,但我没有这样做,因为我在这里找不到任何模式.
As you can see there is a missing piece in the output file i.e. I am not able to open/close the do-end block properly. For this I need to make use of the node numbers but I am failing to so as I am unable to find any pattern here.
谁能帮我解决这个问题.
Could anyone of you please help me with this query.
除此之外,像决策树分类器一样,我不能提取上面第二个链接中提到的 children_left、children_right、阈值.我已经成功提取了GBM的每一棵树
Apart from this, like decisiontreeclassifier can I not extract the children_left, children_right, threshold value as mentioned in the above 2nd link. I have successfully extracted each tree of GBM
但是我没有找到任何有用的函数可以用来提取每棵树的值和规则.如果我能以与 DecisionTreeclassifier 类似的方式使用 grapviz 对象,请提供帮助.
but I didn't find any useful function which I can use to extract the value and rules of each tree. Kindly help if I can use the grapviz object in a similar way of DecisionTreeclassifier.
或
用任何其他可以解决我的目的的方法来帮助我.
Help me with any other method which can solve my purpose.
推荐答案
不需要使用graphviz导出来访问决策树数据.model.estimators_
包含模型所包含的所有单个分类器.对于 GradientBoostingClassifier,这是一个形状为 (n_estimators, n_classes) 的 2D numpy 数组,每个项目都是一个 DecisionTreeRegressor.
There is no need to use the graphviz export to access the decision tree data. model.estimators_
contains all the individual classifiers that the model consists of. In the case of a GradientBoostingClassifier, this is a 2D numpy array with shape (n_estimators, n_classes), and each item is a DecisionTreeRegressor.
每个决策树都有一个属性 _tree
和 了解决策树结构 展示了如何从该对象中取出节点、阈值和子对象.
Each decision tree has a property _tree
and Understanding the decision tree structure shows how to get out the nodes, thresholds and children from that object.
为每棵树输出如下内容:
Outputs something like this for each tree:
这篇关于从 GradientBoostingClassifier 中提取决策规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!