private void picImage_Click(object sender, EventArgs e) { MouseEventArgs me = (MouseEventArgs)e; if (me.Button == MouseButtons.Left) { double predicted = KNearestNeighboursManager.Classify(new double[] { Convert.ToDouble(me.X - 7), Convert.ToDouble(me.Y - 7) }, dataSetList.ToArray(), numClasses, k); dataSetList.Add(new double[] { Convert.ToDouble(me.X - 7), Convert.ToDouble(me.Y - 7), predicted }); } else if (me.Button == MouseButtons.Right) { var poz = dataSetList.FindIndex(c => c[0] <= me.X + 8 && c[0] >= me.X - 8 && c[1] <= me.Y + 8 && c[1] >= me.Y - 8); if (poz != -1) { dataSetList.RemoveAt(poz); } } picImage.Invalidate(); }
private void event_keyDown(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { List <int> errors = new List <int>(); for (int i = 1; i < dataSetList.Count; i++) { errors.Add(0); foreach (var point in dataSetList) { var value = KNearestNeighboursManager.Classify(new double[] { point[0], point[1] }, dataSetList.ToArray(), numClasses, i); if (value != point[2]) { errors[i - 1]++; } } } this.label2.Text += errors.IndexOf(errors.Min()) + 1; } picImage.Invalidate(); }