コード例 #1
0
 public string Go(PointXD test)
 {
     foreach (KeyValuePair <object, DecisionTree> pair in Branches)
     {
         if (AboutEqual(pair.Key, (test.Attributes[Question])))
         {
             return(pair.Value.Go(test));
         }
     }
     return(Answer ?? Go(test));
 }
コード例 #2
0
        private DecisionTree HandlePoint(PointXD point, int paramCount = 0)
        {
            if (paramCount == point.Count)
            {
                Answer = point.Class;
                return(this);
            }

            Question = paramCount;
            object       param = point.Attributes[paramCount];
            DecisionTree tree  = Branches.ContainsKey(param) ? Branches[param] : new DecisionTree();

            Branches[param] = tree.HandlePoint(point, ++paramCount);

            return(this);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            List <PointXD> data = Read("test.txt");
            PointXD        test = new PointXD(null, 6.3, 2.7, 5.5, 2.1);

            DecisionTree tree = DecisionTree.Build(data);

            tree.Print();
            string winnerClass = MakeDecision(tree, test);

            Console.WriteLine("Found class: " + winnerClass);
            Console.WriteLine();

            // пример из методички
            data = Read("test2.txt");
            test = new PointXD(null, "<=30", "средний", "да", "хороший");
            tree = DecisionTree.Build(data);
            tree.Print();
            winnerClass = MakeDecision(tree, test);
            Console.WriteLine("Found class: " + winnerClass);
        }
コード例 #4
0
 private static string MakeDecision(DecisionTree tree, PointXD test) => tree.Go(test);