Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var constants = new Constants();

            if (CommandLine.Parser.Default.ParseArguments(args, constants))
            {
                var data        = ReadData("training.csv");
                var treeService = new TreeService(constants);
                var t           = new Node();
                if (constants.DecisionAlgorithm == "information-gain")
                {
                    Console.WriteLine("Building tree using information gain...");
                }
                else if (constants.DecisionAlgorithm == "gini-index")
                {
                    Console.WriteLine("Building tree using gini index...");
                }
                else
                {
                    Console.WriteLine("Building tree with gini and information gain");
                }

                t = treeService.BuildTree(data, constants.DecisionAlgorithm);

                Console.WriteLine("Traversing Tree...");
                var i = treeService.DetermineAccuracy(data, t);
                Console.WriteLine("Our tree was " + i + "% accurate!");


                //run on testing data
                data = ReadData("testing.csv");
                int      length = data.Count;
                string[] lines  = new string[length + 1];
                lines[0] = "id,class";
                for (int k = 0; k < length; k++)
                {
                    var c = treeService.TraverseTree(data[k], t);
                    lines[k + 1] = data[k].id + "," + c;
                }
                System.IO.File.WriteAllLines(@"Data\results.csv", lines);
            }
            else
            {
                Console.WriteLine("Arguments failed to parse. Program exiting.");
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }