Exemplo n.º 1
0
        public double Distance(SCP s2)
        {
            double power = 0;

            for (int i = 0; i < points.Length; i++)
            {
                power += Math.Pow(points[i] - s2.points[i], 2);
            }
            return(power);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <SCP> list = new List <SCP>();

            string[] lines = File.ReadAllLines("..\\..\\..\\iris_training.txt");
            foreach (string line in lines)
            {
                SCP p = new SCP(line, true);
                list.Add(p);
            }
            Console.WriteLine("\nPodaj k");
            int k = int.Parse(Console.ReadLine());

            string[] newPoints = File.ReadAllLines("..\\..\\..\\iris_test.txt");
            void przeliczDlaK(int k)
            {
                int pointCounter   = 0;
                int correctAnswers = 0;

                foreach (string line in newPoints)
                {
                    SCP point = new SCP(line, true);
                    if (point.Nearest(list, k) == point.type)
                    {
                        correctAnswers++;
                    }
                    pointCounter++;
                }
                Console.WriteLine(string.Format("dla k: {0,3}, prawidłowo zakwalifikowano {1,2} czyli {2:N2}%", k, correctAnswers, correctAnswers / (double)pointCounter * 100));
            }

            //for(int i = 1; i <= list.Count; i++)przeliczDlaK(i);
            przeliczDlaK(k);
            while (true)
            {
                Console.WriteLine("\nPodaj punkty ('z' dla wyjscia)");
                try
                {
                    SCP myPoint = new SCP(Console.ReadLine(), false);
                    Console.WriteLine("Wybrano typ: " + myPoint.Nearest(list, k));
                }
                catch (FormatException e) { return; }
            }
        }