[英]Automated Decision Making Using Decision Tree Classifier
I'm trying to code a decision making process which otherwise require extensive IF ELSE scripting, and I'm wondering if it's possible to express the whole process in a form of root, decision and leave nodes in scikit learn's decision tree classifier.我正在尝试编写一个决策过程,否则需要大量的 IF ELSE 脚本,我想知道是否可以在 scikit 学习的决策树分类器中以根、决策和离开节点的形式表达整个过程。
Note that there is no training involved, just a direct user-definition of the nodes.请注意,不涉及培训,只是节点的直接用户定义。
I get the intent, but a decision tree is a very particular algorithm with goals much different than yours.我明白了,但是决策树是一种非常特殊的算法,其目标与您的目标大不相同。 Depending on the kind of conditions and how many of them you have, you should first evaluate if a map (dictionary) is more appropiate.
根据条件的种类和条件的多少,您应该首先评估 map(字典)是否更合适。 If you still think you need to go ahead with a tree structure, you should implement your own tree as @akshay-sehgal said.
如果你仍然认为你需要 go 提前使用树结构,你应该按照@akshay-sehgal 所说的那样实现你自己的树。
You can use this simple Node
class that stores the condition as a lambda, in the attribute left_condition
.您可以使用这个简单的
Node
class,它在属性left_condition
。 If left_condition
is None, the node is a leaf and returns value
.如果
left_condition
为 None,则节点为叶子并返回value
。 Otherwise it's a decision node and goes either to the left
or right
node, as you can see in the get_value
function:否则,它是一个决策节点,会转到
left
或right
节点,如您在get_value
function 中所见:
class Node:
def __init__(left_condition = None, value = None, left = None, right= None):
self.left_condition = left_condition
self.value = value
self.left = left
self.right = right
def get_value(tree,data):
node = tree
while node.left_condition is not None:
if left_condition(data):
node = node.left
else:
node = node.right
return node.value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.