예제 #1
0
        private void btn_hesapla_Click(object sender, EventArgs e)
        {
            if (Kontrol())
            {
                double[] yeniVeri = new double[v.Data[0].Length - 1];
                string[] veri     = txt_yeniVeri.Text.Split(';');
                if (v.Data[0].Length - 1 == veri.Length)
                {
                    for (int i = 0; i < veri.Length; i++)
                    {
                        yeniVeri[i] = double.Parse(veri[i]);
                    }
                    KNN knn = new KNN(int.Parse(txt_knnKDegeri.Text), v, SecilenMetrik());
                    var r   = knn.Classifier2(yeniVeri);

                    DataGridVeriEkle(dataGridView3, r.Item1.ToArray());
                    MessageBox.Show("Tahmin Edilen Sınıf: " + r.Item2);
                }
                else
                {
                    MessageBox.Show("Veri Setinin kolon sayısı ile girilen yeni değer dizisinin uzunluğu(" + veri.Length.ToString() + ") birbiriyle uyuşmamaktadır.");
                }
            }
            else
            {
                MessageBox.Show("Boş alanlar var kontrol ediniz.");
            }
        }
예제 #2
0
        private void btn_hesapla2_Click(object sender, EventArgs e)
        {
            if (Kontrol())
            {
                DataGridVeriTemizle(dataGridView1);
                DataGridVeriTemizle(dataGridView2);
                if (cbox_veriyiBolmeTipi.SelectedIndex == 0)
                {
                    KFold kf = new KFold(v.Data, int.Parse(txt_bolmeDegeri.Text));
                    kf.Fold();
                    double[] accScore = new double[int.Parse(txt_bolmeDegeri.Text)];
                    for (int i = 0; i < int.Parse(txt_bolmeDegeri.Text); i++)
                    {
                        var currentFoldData = kf.FoldCalculate(i);
                        v.xTrain = cbox_normalizasyon.Checked ? new FeatureScaling().Normalize(currentFoldData.xTrain) : currentFoldData.xTrain;
                        v.yTrain = currentFoldData.yTrain;
                        v.xTest  = cbox_normalizasyon.Checked ? new FeatureScaling().Normalize(currentFoldData.xTest) : currentFoldData.xTest;
                        v.yTest  = currentFoldData.yTest;
                        KNN knn = new KNN(int.Parse(txt_knnKDegeri.Text), v, SecilenMetrik());
                        accScore[i] = knn.Classifier();

                        DataGridVeriEkle(dataGridView1, v.xTrain);
                        DataGridVeriEkle(dataGridView2, v.xTest);
                    }
                    DataGridVeriTemizle(dataGridView3);
                    dataGridView3.DataSource = accScore.Select((x, y) => new {
                        FoldNumber = y + 1,
                        AccScore   = x
                    }).ToList();

                    var accuracyScore = accScore.Sum() / int.Parse(txt_bolmeDegeri.Text);
                    MessageBox.Show("Accruacy Score: " + accuracyScore.ToString());
                }
                else
                {
                    double         accScore        = 0;
                    RandomSampling rs              = new RandomSampling(data, double.Parse(txt_bolmeDegeri.Text));
                    var            currentFoldData = rs.Split2();
                    v.xTrain = cbox_normalizasyon.Checked ? new FeatureScaling().Normalize(currentFoldData.xTrain) : currentFoldData.xTrain;
                    v.yTrain = currentFoldData.yTrain;
                    v.xTest  = cbox_normalizasyon.Checked ? new FeatureScaling().Normalize(currentFoldData.xTest) : currentFoldData.xTest;
                    v.yTest  = currentFoldData.yTest;
                    KNN knn = new KNN(int.Parse(txt_knnKDegeri.Text), v, SecilenMetrik());
                    accScore = knn.Classifier();
                    DataGridVeriEkle(dataGridView1, v.xTrain);
                    DataGridVeriEkle(dataGridView2, v.xTest);
                    DataGridVeriTemizle(dataGridView3);
                    MessageBox.Show("Accruacy Score: " + accScore.ToString());
                }
            }
            else
            {
                MessageBox.Show("Boş alanlar var kontrol ediniz.");
            }
        }