private void button1_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); dataGridView1.Refresh(); int index = 0; string path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Output.txt"); StreamWriter file = new StreamWriter(@path); KNearestNeighbour knnClassifier = new KNearestNeighbour(10, Main.trainingImagesFeatures, Main.trainingLabels); this.confusionMatrix = new int[10, 10]; var watch = Stopwatch.StartNew(); if (ClassifierType == "KNN") { while (index != NumberOfImages) { int classIndex = knnClassifier.classify(K, Mode.testImagesFeatures[index]); this.confusionMatrix[Mode.testLabels[index], classIndex]++; string[] output = { index.ToString(), Mode.testLabels[index].ToString(), classIndex.ToString() }; this.dataGridView1.Rows.Add(output); string outputFile = "Image# " + index.ToString() + "\t Predection: " + classIndex.ToString() + "\t Label: " + Mode.testLabels[index] + "\n"; file.WriteLine(outputFile); index++; } watch.Stop(); file.WriteLine(watch.ElapsedMilliseconds.ToString()); Process proc = Process.GetCurrentProcess(); file.WriteLine((proc.PrivateMemorySize64 / 1024).ToString()); } else if (ClassifierType == "KNN Modified") { while (index != NumberOfImages) { int classIndex = knnClassifier.classifyModified(Mode.testImagesFeatures[index]); this.confusionMatrix[Mode.testLabels[index], classIndex]++; string[] output = { index.ToString(), Mode.testLabels[index].ToString(), classIndex.ToString() }; this.dataGridView1.Rows.Add(output); string outputFile = "Image# " + index.ToString() + "\t Predection: " + classIndex.ToString() + "\t Label: " + Mode.testLabels[index] + "\n"; file.WriteLine(outputFile); index++; } watch.Stop(); file.WriteLine(watch.ElapsedMilliseconds.ToString()); Process proc = Process.GetCurrentProcess(); file.WriteLine((proc.PrivateMemorySize64 / 1024).ToString()); } file.Close(); ConfusionMatrixForm cmf = new ConfusionMatrixForm(); cmf.Show(); cmf.setConfusionMatrix(this.confusionMatrix, watch.ElapsedMilliseconds.ToString()); }