示例#1
0
        public DecisionTree createTree()
        {
            if (data.checkIfPlain())
            {
                DecisionTree toReturn = new DecisionTree(0, "-1", "-1", data.DataValues[0].DataClass);
                return(toReturn);
            }

            Tuple <int, string> split = data.findBestSplit();
            string nodeSign;

            if (data.DataValues[0].Attributes[split.Item1].isNumerical())
            {
                nodeSign = "<=";
            }
            else
            {
                nodeSign = "=";
            }
            DecisionTree node = new DecisionTree(split.Item1, nodeSign, split.Item2);

            Tuple <DataSet, DataSet> newTables = data.splitTable(split.Item1, split.Item2);
            Sprint left  = new Sprint(newTables.Item1);
            Sprint right = new Sprint(newTables.Item2);

            node.addChild('l', left.createTree());
            node.addChild('r', right.createTree());

            return(node);
        }
示例#2
0
        public void createTree(string trainingPath, string trainingName, char separator)
        {
            Globals.stopWatch.Start();
            DataSet trainingSet = new DataSet(trainingPath + "\\" + trainingName + ".txt", separator, true);

            Globals.stopWatch.Stop();
            Globals.printElapsedTimeResetWatch(Globals.stopWatch.Elapsed, "Training data set");
            Globals.stopWatch.Start();
            Sprint sprint = new Sprint(trainingSet);

            Globals.stopWatch.Stop();
            Globals.printElapsedTimeResetWatch(Globals.stopWatch.Elapsed, "Sprint created");
            Globals.stopWatch.Start();
            DecisionTree tree = sprint.createTree();

            Globals.stopWatch.Stop();
            Globals.printElapsedTimeResetWatch(Globals.stopWatch.Elapsed, "Tree created");
            Globals.stopWatch.Start();
            tree.saveToTxt(trainingPath, "Decision_Tree_" + trainingName);
            Globals.stopWatch.Stop();
            Globals.printElapsedTimeResetWatch(Globals.stopWatch.Elapsed, "Saving tree to file");
        }