예제 #1
0
 public Centroid(Iris i)
 {
     F1 = i.SepalL;
     F2 = i.SepalW;
     F3 = i.PetalL;
     F4 = i.PetalW;
 }
예제 #2
0
 public Centroid(Iris i, string name)
 {
     F1 = i.SepalL;
     F2 = i.SepalW;
     F3 = i.PetalL;
     F4 = i.PetalW;
 }
        public static Centroid CountDistAndAssignCentroid(Iris iris, Centroid irisSetosa, Centroid irisVersicolor, Centroid irisVerginica)
        {
            bool   status = true;
            double dist1 = 0, dist2 = 0, dist3 = 0;

            dist1 = CountDist(iris, irisSetosa);
            dist2 = CountDist(iris, irisVersicolor);
            dist3 = CountDist(iris, irisVerginica);

            if (dist1 < dist2 && dist1 < dist3)
            {
                return(irisSetosa);
            }
            else if (dist2 < dist1 && dist2 < dist3)
            {
                return(irisVersicolor);
            }
            else
            {
                return(irisVerginica);
            }
        }
        private static double CountDist(Iris iris, Centroid centroid)
        {
            double distance = Math.Sqrt(Math.Pow((iris.SepalL - (double)centroid.F1), 2) + Math.Pow((iris.SepalW - (double)centroid.F2), 2) + Math.Pow((iris.PetalL - (double)centroid.F3), 2) + Math.Pow((iris.PetalW - (double)centroid.F4), 2));

            return(distance);
        }