Esempio n. 1
0
        public static void Run(string trainingSetPath, string testingSetPath, int numberOfModels, int?randomSeed)
        {
            Trace.TraceInformation("Starting bagging");
            Trace.TraceInformation("TrainingSetPath: {0}", trainingSetPath);
            Trace.TraceInformation("TestingSetPath: {0}", testingSetPath);
            Trace.TraceInformation("Models: {0}", numberOfModels);

            Instances trainingInstances = Diabetes.LoadData(trainingSetPath, Mode.Train);
            Bagging   bagging           = new Bagging();

            bagging.Train(trainingInstances, numberOfModels, randomSeed);
            Instances testingInstances = Diabetes.LoadData(testingSetPath, Mode.Test);

            bagging.TestNonBagging(testingInstances);
            bagging.Test(testingInstances);
        }
Esempio n. 2
0
        public static void GenerateNaiveBayesInputFiles(string trainingInputFile, string testingInputFile, string trainingOutputFile, string testingOutputFile)
        {
            // We don't want to change the naive bayes implementation for spam detection. So, let target attribute 0 = "ham" and 1 = "spam"

            // Training Data

            Instances trainingInstances    = Diabetes.LoadData(trainingInputFile, Mode.Train, Category.Buckets);
            int       targetAttributeIndex = Diabetes.NumAttributes - 1;

            StringBuilder trainingOutput = new StringBuilder();

            for (int i = 0; i < trainingInstances.numInstances(); i++)
            {
                trainingOutput.AppendFormat("{0} {1}", i, trainingInstances.instance(i).value(targetAttributeIndex) == 0 ? "ham" : "spam");

                for (int j = 0; j < trainingInstances.numAttributes() - 1; j++)
                {
                    trainingOutput.AppendFormat(" {0}_{1} {2}", j, trainingInstances.instance(i).value(j), 1);
                    //trainingOutput.AppendFormat(" {0} {1}", j, trainingInstances.instance(i).value(j));
                }

                trainingOutput.AppendLine();
            }

            File.WriteAllText(trainingOutputFile, trainingOutput.ToString());


            // Testing Data

            Instances     testingInstances = Diabetes.LoadData(testingInputFile, Mode.Test, Category.Buckets);
            StringBuilder testingOutput    = new StringBuilder();

            for (int i = 0; i < testingInstances.numInstances(); i++)
            {
                testingOutput.AppendFormat("{0} {1}", i, testingInstances.instance(i).value(targetAttributeIndex) == 0 ? "ham" : "spam");

                for (int j = 0; j < testingInstances.numAttributes() - 1; j++)
                {
                    testingOutput.AppendFormat(" {0}_{1} {2}", j, testingInstances.instance(i).value(j), 1);
                    //testingOutput.AppendFormat(" {0} {1}", j, testingInstances.instance(i).value(j));
                }

                testingOutput.AppendLine();
            }

            File.WriteAllText(testingOutputFile, testingOutput.ToString());
        }