Exemplo n.º 1
0
        static void Main(string[] args)
        {
            IFileLoader fileLoader = new FileLoader.FileLoader();
            var arffFilePath = fileLoader.GetPath(string.Empty);

            IFileProcesser<string> fileProcesser = new SimpleFileProcceser();
            using (var textReader = new StreamReader(arffFilePath, Encoding.UTF8))
            {
                var processedFile = fileProcesser.Process(textReader.ReadToEnd());
                var naiveBayes = new NaiveBayes.NaiveBayes(processedFile, "Drug");
                naiveBayes.TrainFromSet();

                //for (var i = 0; i < processedFile.Data.Count; i++)
                //{
                //    var testData = new TestDataModel(processedFile.Data[i]);
                //    var currentResult = naiveBayes.TestNewData(testData.TestData);

                //    PrintResultValue(currentResult);
                //}

                var testModel = new TestDataModel();
                var result = naiveBayes.TestNewData(testModel.TestData);

                PrintResultValue(result);

                Console.ReadKey();
            };
        }
Exemplo n.º 2
0
        private ResultModel ExecuteNaiveClassiffication(TestDataModel testModel)
        {
            IFileLoader fileLoader = new FileLoader.FileLoader();
            var arffFilePath = fileLoader.GetPath(string.Empty);

            IFileProcesser<string> fileProcesser = new SimpleFileProcceser();
            using (var textReader = new StreamReader(arffFilePath, Encoding.UTF8))
            {
                var processedFile = fileProcesser.Process(textReader.ReadToEnd());
                var naiveBayes = new NaiveBayes.NaiveBayes(processedFile, "Drug");
                naiveBayes.TrainFromSet();
                var currentResult = naiveBayes.TestNewData(testModel.TestData);
                return currentResult;
            }
        }
Exemplo n.º 3
0
        private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var start = System.DateTime.Now;

            IFileLoader fileLoader = new FileLoader.FileLoader();
            var arffFilePath = fileLoader.GetPath(string.Empty);

            IFileProcesser<string> fileProcesser = new SimpleFileProcceser();
            using (var textReader = new StreamReader(arffFilePath, Encoding.UTF8))
            {
                var processedFile = fileProcesser.Process(textReader.ReadToEnd());
                var naiveBayes = new NaiveBayes.NaiveBayes(processedFile, "Drug");
                naiveBayes.TrainFromSet();
                fileLoader.SaveJsonFileToText(JsonConvert.SerializeObject(naiveBayes.GetModel()), string.Empty);
            }

            var end = System.DateTime.Now;
            var difference = end.Subtract(start).TotalMilliseconds;
            MessageBox.Show(@"Processed! in " + difference + " milliseconds", @"Time elapsed", MessageBoxButtons.OK);
        }
Exemplo n.º 4
0
 public void TrainFromSet()
 {
     _naiveBayesModel = new NaiveBayesModel();
     _naiveBayesModel.DataModel = _model;
     _naiveBayesModel.TargetAttribute = _targetAttribute;
     ArffFileProcesser.Attribute targetAttribute = FindTargetAttribute();
     var targetAttribIndex = FindTargetAttribIndex();
     if (targetAttribute != null)
     {
         var totalData = targetAttribute.Values.Count();
         // calculate precision
         CalculatePrecision();
         //calculate probability of the classes identified
         CalculateProbability(targetAttribute, totalData);
     }
     //change foreach continuous values the value according to the formula  value = ParteEntera (original value / precision ) * precision
     //calculate possibilities foreach class within each value of other attribute
     //find the target attribute index
     CreateNormalizedData(targetAttribIndex);
     IFileLoader loader = new FileLoader.FileLoader();
     loader.SaveJsonFileToText(JsonConvert.SerializeObject(_naiveBayesModel), string.Empty);
 }