Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            bool isDebug = false;

            FileHandling.ReadFile(isDebug);
            //DataSet.PrintSimpleStructure();

            Algorithm algorithm = new Algorithm();

            Algorithm.ID3(DataSet.RootNode, new DataBag(DataSet.Instances));
            Printer.BeautifulBorder("ID3:");
            Printer.Print(DataSet.RootNode);

            var b   = new Bayes();
            var con = new ConfusionMatrix();

            Printer.BeautifulBorder("Naïve Bayes:");
            con.PrintMatrix();

            b.PrintLikelihoodTable();

            Console.WriteLine(
                b.ClassifyDataInstance(new DataInstance(new List <string>()
            {
                "rainy", "mild", "normal", "true"
            })));


            if (!isDebug)
            {
                Console.Read();
            }
        }
Ejemplo n.º 2
0
        public ConfusionMatrix()
        {
            var bayes = new Bayes();

            _matrix = new int[_dimensionSize, _dimensionSize];
            var   instanceSum = DataSet.Instances.Count;
            float truePos = 0, trueNeg = 0, falsePos = 0, falseNeg = 0;

            foreach (var instance in DataSet.Instances)
            {
                var outcome = bayes.ClassifyDataInstance(instance);
                if (outcome == instance.Qualifier)
                {
                    truePos++;
                    trueNeg += (_dimensionSize - 1);
                }
                else
                {
                    falsePos++;
                    falseNeg++;
                    trueNeg += (_dimensionSize - 2);
                    //Console.WriteLine($"Wrong: {DataSet.Instances.IndexOf(instance)}");
                }

                _matrix[instance.Qualifier, outcome]++;
            }

            RealAccuracy = (100 * truePos / (truePos + falsePos));
            Accuracy     = (100 * (truePos + trueNeg) / (truePos + trueNeg + falsePos + falseNeg));
        }