Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int iteration = 0;

            while (iteration > numericUpDownClusterNumber.Value)
            {
                List <Iris> irisC1 = new List <Iris>();
                List <Iris> irisC2 = new List <Iris>();
                List <Iris> irisC3 = new List <Iris>();
                foreach (Iris i in listOfIris)
                {
                    i.Centroid = CentroidMover.CountDistAndAssignCentroid(i, centroid1, centroid2, centroid3);
                    if (i.Centroid == centroid1)
                    {
                        irisC1.Add(i);
                    }
                    else if (i.Centroid == centroid2)
                    {
                        irisC2.Add(i);
                    }
                    else if (i.Centroid == centroid3)
                    {
                        irisC3.Add(i);
                    }
                }
                centroid1 = Centroid.HitungPosisiCentroid(irisC1);
                centroid2 = Centroid.HitungPosisiCentroid(irisC2);
                centroid3 = Centroid.HitungPosisiCentroid(irisC3);
                switch (iteration)
                {
                case (5):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;

                case (10):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;

                case (15):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;
                }
                iteration++;
            }
            foreach (Iris i in listOfIris)
            {
                if (centroid1 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Setosa");
                }
                else if (centroid2 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Versicolor");
                }
                else if (centroid3 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Virginica");
                }
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            listSSE = new List <double>();
            int         iteration = 0;
            List <Iris> irisC1    = new List <Iris>();
            List <Iris> irisC2    = new List <Iris>();
            List <Iris> irisC3    = new List <Iris>();

            while (iteration < numericUpDownClusterNumber.Value)
            {
                irisC1 = new List <Iris>();
                irisC2 = new List <Iris>();
                irisC3 = new List <Iris>();
                foreach (Iris i in listOfIris)
                {
                    i.Centroid = CentroidMover.CountDistAndAssignCentroid(i, centroid1, centroid2, centroid3);
                    if (i.Centroid == centroid1)
                    {
                        irisC1.Add(i);
                    }
                    else if (i.Centroid == centroid2)
                    {
                        irisC2.Add(i);
                    }
                    else if (i.Centroid == centroid3)
                    {
                        irisC3.Add(i);
                    }
                }
                centroid1 = Centroid.HitungPosisiCentroid(irisC1, "Setosa");
                centroid2 = Centroid.HitungPosisiCentroid(irisC2, "Versicolor");
                centroid3 = Centroid.HitungPosisiCentroid(irisC3, "Virginica");
                iteration++;
                listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                listSSE.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
            }
            dataGridViewDataCluster.Rows.Clear();
            foreach (Iris i in listOfIris)
            {
                if (centroid1.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Setosa");
                }
                else if (centroid2.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Versicolor");
                }
                else if (centroid3.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Virginica");
                }
            }
            MessageBox.Show("Setosa : " + irisC1.Count.ToString() + "\nVersicolor : " + irisC2.Count.ToString() + "\nVirginica : " + irisC3.Count.ToString(), "Setosa, VersiColor, and Virginica Amount :");
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            line = "";
            int         iteration = 0;
            List <Iris> irisC1    = new List <Iris>();
            List <Iris> irisC2    = new List <Iris>();
            List <Iris> irisC3    = new List <Iris>();

            while (iteration < numericUpDownClusterNumber.Value)
            {
                irisC1 = new List <Iris>();
                irisC2 = new List <Iris>();
                irisC3 = new List <Iris>();
                foreach (Iris i in listOfIris)
                {
                    i.Centroid = CentroidMover.CountDistAndAssignCentroid(i, centroid1, centroid2, centroid3);
                    if (i.Centroid == centroid1)
                    {
                        irisC1.Add(i);
                    }
                    else if (i.Centroid == centroid2)
                    {
                        irisC2.Add(i);
                    }
                    else if (i.Centroid == centroid3)
                    {
                        irisC3.Add(i);
                    }
                }
                centroid1 = Centroid.HitungPosisiCentroid(irisC1, "Setosa");
                centroid2 = Centroid.HitungPosisiCentroid(irisC2, "Versicolor");
                centroid3 = Centroid.HitungPosisiCentroid(irisC3, "Virginica");
                iteration++;
                line += CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3).ToString();
                line += "\n";
            }
            MessageBox.Show(irisC1.Count.ToString(), irisC2.Count.ToString() + " " + irisC3.Count.ToString());
            foreach (Iris i in listOfIris)
            {
                if (centroid1 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Setosa");
                }
                else if (centroid2 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Versicolor");
                }
                else if (centroid3 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Virginica");
                }
            }
        }
Beispiel #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            listSSE = new List <double>();
            int         iteration = 0;
            bool        stop      = false;
            Centroid    c1New;
            Centroid    c2New;
            Centroid    c3New;
            List <Iris> irisC1 = new List <Iris>();
            List <Iris> irisC2 = new List <Iris>();
            List <Iris> irisC3 = new List <Iris>();

            while (stop == false)
            {
                irisC1 = new List <Iris>();
                irisC2 = new List <Iris>();
                irisC3 = new List <Iris>();
                double sseOld = 0;
                foreach (Iris i in listOfIris)
                {
                    if (iteration != 0)
                    {
                        sseOld = CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3);
                    }
                    i.Centroid = CentroidMover.CountDistAndAssignCentroid(i, centroid1, centroid2, centroid3);
                    if (i.Centroid == centroid1)
                    {
                        irisC1.Add(i);
                    }
                    else if (i.Centroid == centroid2)
                    {
                        irisC2.Add(i);
                    }
                    else if (i.Centroid == centroid3)
                    {
                        irisC3.Add(i);
                    }
                }

                c1New = Centroid.HitungPosisiCentroid(irisC1, "Setosa");
                c2New = Centroid.HitungPosisiCentroid(irisC2, "Versicolor");
                c3New = Centroid.HitungPosisiCentroid(irisC3, "Virginica");
                double sseNew = CentroidMover.CalcSSE(listOfIris, c1New, c2New, c3New);
                if (c1New == centroid1 && c2New == centroid2 && c3New == centroid3)
                {
                    stop = true;
                    MessageBox.Show("Your Dataset is finished after  " + iteration.ToString() + " of iteration");
                }

                else if (sseOld == sseNew)
                {
                    stop = true;
                    MessageBox.Show("Your Dataset is finished after  " + iteration.ToString() + " of iteration");
                }

                else
                {
                    centroid1 = c1New;
                    centroid2 = c2New;
                    centroid3 = c3New;
                }

                iteration++;
                listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                listSSE.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
            }
            dataGridViewDataCluster.Rows.Clear();
            foreach (Iris i in listOfIris)
            {
                if (centroid1.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Setosa");
                }
                else if (centroid2.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Versicolor");
                }
                else if (centroid3.Name == i.Centroid.Name)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Virginica");
                }
            }
            MessageBox.Show("Setosa : " + irisC1.Count.ToString() + "\nVersicolor : " + irisC2.Count.ToString() + "\nVirginica : " + irisC3.Count.ToString(), "Setosa, VersiColor, and Virginica Amount :");
        }
Beispiel #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            int      iteration = 0;
            bool     stop      = false;
            Centroid c1New;
            Centroid c2New;
            Centroid c3New;

            while (stop == false)
            {
                List <Iris> irisC1 = new List <Iris>();
                List <Iris> irisC2 = new List <Iris>();
                List <Iris> irisC3 = new List <Iris>();
                foreach (Iris i in listOfIris)
                {
                    i.Centroid = CentroidMover.CountDistAndAssignCentroid(i, centroid1, centroid2, centroid3);
                    if (i.Centroid == centroid1)
                    {
                        irisC1.Add(i);
                    }
                    else if (i.Centroid == centroid2)
                    {
                        irisC2.Add(i);
                    }
                    else if (i.Centroid == centroid3)
                    {
                        irisC3.Add(i);
                    }
                }
                switch (iteration)
                {
                case (5):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;

                case (10):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;

                case (15):
                    listBoxDisplay.Items.Add(CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3));
                    continue;
                }
                iteration++;
                c1New = Centroid.HitungPosisiCentroid(irisC1);
                c2New = Centroid.HitungPosisiCentroid(irisC2);
                c3New = Centroid.HitungPosisiCentroid(irisC3);
                if (c1New == centroid1 && c2New == centroid2 && c3New == centroid3)
                {
                    double sseNew = CentroidMover.CalcSSE(listOfIris, c1New, c2New, c3New);
                    double sseOld = CentroidMover.CalcSSE(listOfIris, centroid1, centroid2, centroid3);
                    if (sseOld == sseNew)
                    {
                        stop = true;
                    }
                }
                else
                {
                    centroid1 = c1New;
                    centroid2 = c2New;
                    centroid3 = c3New;
                }
            }
            foreach (Iris i in listOfIris)
            {
                if (centroid1 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Setosa");
                }
                else if (centroid2 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Versicolor");
                }
                else if (centroid3 == i.Centroid)
                {
                    dataGridViewDataCluster.Rows.Add(i.SepalL, i.SepalW, i.PetalL, i.PetalW, "Virginica");
                }
            }
        }