예제 #1
0
파일: Program.cs 프로젝트: volend/ML
 public DecisionRule Prepend(DecisionRule rule)
 {
     rule.Positive = Positive;
     rule.Label   += Label;
     rule.Func     = x => rule.Func(x) && Func(x);
     return(rule);
 }
예제 #2
0
파일: Program.cs 프로젝트: volend/ML
        public void BuildRuleSets(List <DecisionRule> ruleSets)
        {
            if (IsLeafNode())
            {
                TreeNode node = this; // A leaf node always has a parent unless it's the root
                //var expression = new Stack<string>();
                var ruleExpression = new DecisionRule($" then => {decision()}", x => decision(), decision());

                //expression.Push($" then => {decision()}");
                while (node.parent != null)
                {
                    //expression.Push($" if [Attribute {node.parent.splitAttribute.Name} has Value {node.Value}] and ");
                    var localNode = node;
                    ruleExpression =
                        ruleExpression.Prepend(new DecisionRule(
                                                   $" if [Attribute {node.parent.splitAttribute.Name} has Value {node.Value}] and ",
                                                   x => x[localNode.parent.splitAttribute] == localNode.Value));
                    node = node.parent;
                    //sb.Append($"and Attribute={Attribute}")
                }

                lock (ruleSets)
                {
                    ruleSets.Add(ruleExpression);
                }
            }
            else
            {
                foreach (var childNode in children.Values)
                {
                    childNode.BuildRuleSets(ruleSets);
                }
            }
        }