public ClassifierWReview()
        {
            //runData2 and runData2_1
            //string filedata = System.IO.File.ReadAllText("../runData2.txt");
            string filedata = System.IO.File.ReadAllText("../runData2_1.txt");

            string[] inputColumns =
            {
                "Day", "Outlook", "Temperature", "Humidity", "Wind", "SprintReview"
            };

            string outputColumn = "GoRun";

            DataTable data = new DataTable("Internet Services Run Calculator");

            data.Columns.Add(inputColumns);
            data.Columns.Add(outputColumn);

            string[] lines = filedata.Split(
                new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                data.Rows.Add(line.Split(','));
            }

            //create codebook to turn the strings into number representations
            codebook = new Accord.Statistics.Filters.Codification(data);

            // Translate our training data into integer symbols using our codebook:
            DataTable symbols = codebook.Apply(data);

            int[][] inputs  = symbols.ToJagged <int>("Outlook", "Temperature", "Humidity", "Wind", "SprintReview");
            int[]   outputs = symbols.ToArray <int>("GoRun");

            string[]           decisionVariables = { "Outlook", "Temperature", "Humidity", "Wind", "SprintReview" };
            DecisionVariable[] attributes        = DecisionVariable.FromCodebook(codebook, decisionVariables);
            // Create a teacher ID3 algorithm
            var id3learning = new ID3Learning(attributes);

            tree = id3learning.Learn(inputs, outputs);
            // Compute the training error when predicting training instances
            double error = new ZeroOneLoss(outputs).Loss(tree.Decide(inputs));
        }
Esempio n. 2
0
        //4, 10, 2, 1, 0, 0, 0, 0
        public string BankPrediction(int a, int b, int c, int d, int e, int f, int g, int h, string name)
        {
            string salida = "Vacio";

            try
            {
                var codebook = new Accord.Statistics.Filters.Codification(table);
                System.Data.DataTable symbols = codebook.Apply(table);

                int[][] inputs  = DataTableToMatrix(symbols, new string[] { "AGE", "JOB", "MARITAL", "EDUCATION", "DEBT", "BALANCE", "HOUSING", "LOAN" });
                int[][] outputs = DataTableToMatrix(symbols, new string[] { "DEPOSIT" });
                int[]   output  = new int[outputs.Length];
                for (int i = 0; i < outputs.Length; i++)
                {
                    output[i] = outputs[i][0];
                }

                ID3Learning teacher = new ID3Learning()
                {
                    new DecisionVariable("AGE", 5),
                    new DecisionVariable("JOB", 12),
                    new DecisionVariable("MARITAL", 3),
                    new DecisionVariable("EDUCATION", 4),
                    new DecisionVariable("DEBT", 2),
                    new DecisionVariable("BALANCE", 6),
                    new DecisionVariable("HOUSING", 2),
                    new DecisionVariable("LOAN", 2)
                };

                DecisionTree tree = teacher.Learn(inputs, output);

                //mandar la variable error a un label que me muestre el error que tiene el arbol
                double error = new Accord.Math.Optimization.Losses.ZeroOneLoss(output).Loss(tree.Decide(inputs));
                double ep    = Math.Floor(error * 100);
                errorLabel.Text = ep + "%" + " " + "-" + " " + "(" + error + ")";


                int[] input      = new int[] { a, b, c, d, e, f, g, h };
                int   prediccion = tree.Decide(input);

                string predijo = prediccion == 1 ? "yes" : "no";
                if (predijo.Equals("yes"))
                {
                    outputLabel.ForeColor = Color.FromArgb(0, 255, 0);
                }
                else if (predijo.Equals("no"))
                {
                    outputLabel.ForeColor = Color.FromArgb(255, 0, 0);
                }
                outputLabel.Text = predijo;
                salida           = predijo;

                subjectLabel.Text = "for" + " " + name + " " + "the prediction is";
            }
            catch (Exception) {
                string message = "Yo cannot make predictions without\nloading the data";
                string title   = "Warning";
                MessageBox.Show(message, title);
            }
            return(salida);
        }