Пример #1
0
        static void Main(string[] args)
        {
            TrainingEntry entry1 = new TrainingEntry("AIR", new string[] { "SUNNY", "RAINY", "CLOUDY" });
            TrainingEntry entry2 = new TrainingEntry("HEAT", new string[] { "HOT", "WARM", "COLD" });
            TrainingEntry entry3 = new TrainingEntry("HUMIDITY", new string[] { "HIGH", "NORMAL" });
            TrainingEntry entry4 = new TrainingEntry("WIND", new string[] { "LIGHT", "STRONG" });

            TrainingSet set = new TrainingSet("GAME", entry1, entry2, entry3, entry4);

            set.AddSample(new TrainingSample(false, "SUNNY", "HOT", "HIGH", "LIGHT"));
            set.AddSample(new TrainingSample(false, "SUNNY", "HOT", "HIGH", "STRONG"));
            set.AddSample(new TrainingSample(true, "CLOUDY", "HOT", "HIGH", "LIGHT"));
            set.AddSample(new TrainingSample(true, "RAINY", "WARM", "HIGH", "LIGHT"));
            set.AddSample(new TrainingSample(true, "RAINY", "COLD", "NORMAL", "LIGHT"));
            set.AddSample(new TrainingSample(false, "RAINY", "COLD", "NORMAL", "STRONG"));
            set.AddSample(new TrainingSample(true, "CLOUDY", "COLD", "NORMAL", "STRONG"));
            set.AddSample(new TrainingSample(false, "SUNNY", "WARM", "HIGH", "LIGHT"));
            set.AddSample(new TrainingSample(true, "SUNNY", "COLD", "NORMAL", "LIGHT"));
            set.AddSample(new TrainingSample(true, "RAINY", "WARM", "NORMAL", "LIGHT"));
            set.AddSample(new TrainingSample(true, "SUNNY", "WARM", "NORMAL", "STRONG"));
            set.AddSample(new TrainingSample(true, "CLOUDY", "WARM", "HIGH", "STRONG"));
            set.AddSample(new TrainingSample(true, "CLOUDY", "HOT", "NORMAL", "LIGHT"));
            set.AddSample(new TrainingSample(false, "RAINY", "WARM", "HIGH", "STRONG"));
            set.Lock();

            Trainer trainer = new Trainer(set);

            trainer.TrainID3(set);

            Console.ReadKey();
        }
Пример #2
0
        public void TrainID3(TrainingSet set)
        {
            string master = this.CalculateHead(set);

            Console.WriteLine("HEAD NODE = " + master);
            Console.WriteLine();

            StringBuilder sb = new StringBuilder(1000);

            for (int i = 0; i < set.Entries.Length; i++)
            {
                TrainingEntry current = set.Entries[i];

                if (current.Name.Equals(master, StringComparison.InvariantCultureIgnoreCase))
                {
                    for (int j = 0; j < current.Values.Length; j++)
                    {
                        string currentName = current.Values[j];

                        TrainingSet currentExcept = this.GetExceptBranch(set, currentName);
                        string      subBranch     = CalculateHead(currentExcept);
                        string      subName       = currentName;

                        sb.AppendLine("+ VALUE = " + subName);

                        if (!subBranch.Equals(master))
                        {
                            sb.AppendLine("|");
                            sb.AppendLine("|");
                            sb.AppendLine("--------- SUB NODE = " + subBranch);

                            PrintSubBranch(currentExcept, sb, subBranch);
                            //this.TrainID3(currentExcept);

                            sb.AppendLine("|");
                            sb.AppendLine("|");
                        }
                        else
                        {
                            sb.AppendLine("(" + CalculateResult(currentExcept, subName) + ")");
                        }
                        //Console.WriteLine("name = " + currentName + "\t\t sub = " + subName + " -- scale = " + currentScale);
                    }
                }
            }
            Console.WriteLine(sb.ToString());
        }