public ScoreModel(TrainModel trainedModel, int K = 3)
 {
     if (!trainedModel.Trained)
         throw new Exception("TrainModel must be trained first");
     this.trainedModel = trainedModel;
     ConfussionMatrix = new int[trainedModel.NumberofClasses, trainedModel.NumberofClasses];
     if (trainedModel.cType == ClassifierType.Bayesian)
         classifier = new BayesianClassifier(trainedModel);
     else if (trainedModel.cType == ClassifierType.KNearestNeighbour)
         classifier = new KNearestNeighbour(trainedModel, K);
 }
示例#2
0
 public ScoreModel(TrainModel trainedModel, int K = 3)
 {
     if (!trainedModel.Trained)
     {
         throw new Exception("TrainModel must be trained first");
     }
     this.trainedModel = trainedModel;
     ConfussionMatrix  = new int[trainedModel.NumberofClasses, trainedModel.NumberofClasses];
     if (trainedModel.cType == ClassifierType.Bayesian)
     {
         classifier = new BayesianClassifier(trainedModel);
     }
     else if (trainedModel.cType == ClassifierType.KNearestNeighbour)
     {
         classifier = new KNearestNeighbour(trainedModel, K);
     }
 }
 private void button2_Click(object sender, EventArgs e)
 {
     List<Data> Trainingdataset = Utility.LoadDataset(DatasetType.Training);
     List<Data> Testingingdataset = Utility.LoadDataset(DatasetType.Testing);
     TrainModel train = null;
     if (comboBox1.SelectedIndex == 0)
         train = new TrainModel(ViewModel.FeatureExtraction.FeatureExtractionType.EuclideanDistance, ClassifierType.Bayesian);
     else if (comboBox1.SelectedIndex == 1)
         train = new TrainModel(ViewModel.FeatureExtraction.FeatureExtractionType.EuclideanDistance, ClassifierType.KNearestNeighbour);
     train.Train(Trainingdataset);
     ScoreModel score = new ScoreModel(train, int.Parse(KNNTextBox.Text));
     score.Score(Testingingdataset);
     dataGridView1.Rows.Clear();
     for (int i = 0; i < score.ConfussionMatrix.GetLength(0); ++i)
     {
         string[] arr = new string[score.ConfussionMatrix.GetLength(1)];
         for (int j = 0; j < score.ConfussionMatrix.GetLength(1); ++j)
             arr[j] = score.ConfussionMatrix[i, j].ToString();
         dataGridView1.Rows.Add(arr);
     }
     OverallAccuracyLabel.Text = score.Accuracy.ToString();
 }
        private void ClassificationButton_Click(object sender, EventArgs e)
        {
            List<Data> Trainingdataset = Utility.LoadDataset(DatasetType.Training);
            TrainModel train = null;
            if (comboBox1.SelectedIndex == 0)
                train = new TrainModel(ViewModel.FeatureExtraction.FeatureExtractionType.EuclideanDistance, ClassifierType.Bayesian);
            else if (comboBox1.SelectedIndex == 1)
                train = new TrainModel(ViewModel.FeatureExtraction.FeatureExtractionType.EuclideanDistance, ClassifierType.KNearestNeighbour);
            train.Train(Trainingdataset);
            OpenFileDialog f = new OpenFileDialog();
            if (DialogResult.OK == f.ShowDialog())
            {

                ScoreModel score = new ScoreModel(train, int.Parse(KNNTextBox.Text));
                List<Vector2> features = Utility.LoadPoints(f.FileName);

                int estimatedClass = score.Classify(features);
                ExpectedClassLabel.Text = estimatedClass.ToString();
                AppModel app = new AppModel(@"C:\Program Files (x86)\Notepad++\notepad++.exe");
                try
                {
                    if (estimatedClass == 0)
                        app.Close();
                    else if (estimatedClass == 1)
                        app.Minimize();
                    else if (estimatedClass == 2)
                        app.Open();
                    else if (estimatedClass == 3)
                        app.Restore();
                }
                catch
                {
                    MessageBox.Show("Couldn't take that action, please make sure that the specified program is already opened");
                }
            }
            /*for(int i=0;i<40;)
            {
                Vector2 a = new Vector2();
                a.x = double.Parse(inputarr[i++].Text);
                a.y = double.Parse(inputarr[i++].Text);
                features.Add(a);
            }*/
        }