예제 #1
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.");
            }
        }
예제 #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     var data = Veri.Oku(@"../../wine_data.txt", ';');
     var kf   = new KFold(data, 4);
 }