Пример #1
0
 public TrainingSet(string outputName, TrainingEntry c45Entry, params TrainingEntry[] entries)
 {
     this.Samples    = new List <TrainingSample>();
     this.OutputName = outputName;
     this.C45Entry   = c45Entry;
     this.Entries    = entries;
 }
Пример #2
0
        static void Main(string[] args)
        {
            TrainingEntry entry1 = new TrainingEntry("AGE", null);
            TrainingEntry entry2 = new TrainingEntry("MODEL", new string[] { "X3", "X5" });
            TrainingEntry entry3 = new TrainingEntry("GENDER", new string[] { "MALE", "FEMALE" });

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

            set.AddSample(new TrainingSample(false, 21, "X5", "MALE"));
            set.AddSample(new TrainingSample(true, 19, "X3", "FEMALE"));
            set.AddSample(new TrainingSample(false, 22, "X5", "MALE"));
            set.AddSample(new TrainingSample(true, 21, "X3", "MALE"));
            set.AddSample(new TrainingSample(true, 30, "X3", "MALE"));
            set.AddSample(new TrainingSample(false, 60, "X3", "FEMALE"));
            set.AddSample(new TrainingSample(false, 45, "X3", "FEMALE"));
            set.AddSample(new TrainingSample(false, 55, "X3", "MALE"));
            set.Lock();

            Trainer trainer = new Trainer(set);

            trainer.TrainID3(set);

            Console.ReadKey();
        }
Пример #3
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 (i == 0)
                {
                    sb.AppendLine(GetHeadC45Name(set) + " <= " + GetHeadC45(set));
                }

                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);
                        TrainingSet currentExcept2 = GetExceptLowerBranch(currentExcept, GetHeadC45(set));

                        string subBranch = CalculateHead(currentExcept2);
                        string subName   = currentName;

                        sb.AppendLine("--------- SUB NODE = " + subBranch);
                        sb.AppendLine("\t\t VALUE = " + subName);



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

                            PrintSubBranch(currentExcept2, sb, subBranch);

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

                if (i == 0)
                {
                    sb.AppendLine(GetHeadC45Name(set) + " > " + GetHeadC45(set));
                }
                if (i == 0)
                {
                    sb.AppendLine("(False)");
                }
            }
            Console.WriteLine(sb.ToString());
        }