Example #1
0
        public static void classifierTwo(string classifierFileName, string predictionModel)
        {
            FileReader javaFileReader = new FileReader(classifierFileName);

            weka.core.Instances wekaInsts = new weka.core.Instances(javaFileReader);
            javaFileReader.close();

            wekaInsts.setClassIndex(wekaInsts.numAttributes() - 1);



            //Classifier nbTree = (Classifier)SerializationHelper.read(Model) as J48;

            Instances testDataSet = new Instances(new BufferedReader(new FileReader(classifierFileName)));

            testDataSet.setClassIndex(wekaInsts.numAttributes() - 1);
            //testDataSet.setClassIndex(10);
            Evaluation evaluation = new Evaluation(testDataSet);


            J48 model = new J48();

            //Classifier myClassifier = (Classifier)SerializationHelper.read(Model) as NaiveBayes;
            //Classifier myClassifier = new NaiveBayes();


            for (int i = 0; i < testDataSet.numInstances(); i++)
            {
                Instance instance = testDataSet.instance(i);
                //evaluation.evaluateModelOnceAndRecordPrediction(myClassifier, instance);
                //evaluation.evaluateModelOnce(myClassifier, instance);
            }

            foreach (object o in evaluation.predictions().toArray())
            {
                NominalPrediction prediction = o as NominalPrediction;
                if (prediction != null)
                {
                    double[] distribution = prediction.distribution();
                    double   predicted    = prediction.predicted();

                    for (int i = 0; i < distribution.Length; i++)
                    {
                        System.Console.WriteLine(distribution[i]);
                    }

                    System.Console.WriteLine(predicted);
                }
            }

            System.Console.WriteLine(evaluation);
            System.Console.ReadKey();
        }
Example #2
0
        public static void classifierOne(string classifierFileName, string predictionModel)
        {
            FileReader javaFileReader = new FileReader(classifierFileName);

            weka.core.Instances wekaInsts = new weka.core.Instances(javaFileReader);
            javaFileReader.close();

            wekaInsts.setClassIndex(wekaInsts.numAttributes() - 1);
            Classifier cl = new SMO();

            //Classifier cl = new NaiveBayes();
            java.util.Random random     = new java.util.Random(1);
            Evaluation       evaluation = new Evaluation(wekaInsts);

            evaluation.crossValidateModel(cl, wekaInsts, 10, random);

            foreach (object o in evaluation.getMetricsToDisplay().toArray())
            {
            }
            int           count = 0;
            StringBuilder sb    = new StringBuilder();

            foreach (object o in evaluation.predictions().toArray())
            {
                NominalPrediction prediction = o as NominalPrediction;
                if (prediction != null)
                {
                    double[] distribution = prediction.distribution();
                    double   predicted    = prediction.predicted();
                    double   actual       = prediction.actual();
                    string   revision     = prediction.getRevision();
                    double   weight       = prediction.weight();
                    double   margine      = prediction.margin();
                    //bool equals = prediction.@equals();

                    string distributions = String.Empty;
                    for (int i = 0; i < distribution.Length; i++)
                    {
                        //System.Console.WriteLine(distribution[i]);
                        distributions += distribution[i];
                    }
                    var predictionLine = String.Format("{0} - {1} - {2} - {3} - {4} - {5}\n", actual, predicted, revision, weight, margine, distributions);
                    sb.Append(predictionLine);
                    //System.Console.WriteLine(predicted);
                }
                count++;
            }
            File_Helper.WriteToFile(sb, predictionModel + "NbCl.txt");
            System.Console.WriteLine(count);
            System.Console.ReadKey();
        }
Example #3
0
        private void ResultButton_Click(object sender, RoutedEventArgs e)
        {
            if (LanguageComboBox.SelectedIndex < 0 ||
                ContributersTextBox?.Text == "" ||
                CommitsTextBox?.Text == "" ||
                StarsTextBox?.Text == "" ||
                ForksTextBox?.Text == "" ||
                BranchesTextBox?.Text == "" ||
                WatchersTextBox?.Text == "" ||
                PullRequestsTextBox?.Text == "" ||
                TotalIssuesTextBox?.Text == "" ||
                OpenIssuesTextBox?.Text == "" ||
                HasDownloadsComboBox.SelectedIndex < 0 ||
                ReleaseCountsTextBox?.Text == ""
                )
            {
                ResultLabel.Content = "Enter All Values";
                return;
            }
            List <string> LinesToWrite = new List <string>();

            LinesToWrite.Add("@relation \"GithubAll\"");
            LinesToWrite.Add("");
            LinesToWrite.Add("@attribute Language { PHP,JAVA,HTML,JavaScript,C}");
            LinesToWrite.Add("@attribute Contributers real");
            LinesToWrite.Add("@attribute Commits real");
            LinesToWrite.Add("@attribute Stars real");
            LinesToWrite.Add("@attribute Forks real");
            LinesToWrite.Add("@attribute Branches real");
            LinesToWrite.Add("@attribute Watchers real");
            LinesToWrite.Add("@attribute PullRequests real");
            LinesToWrite.Add("@attribute TotalIssues real");
            LinesToWrite.Add("@attribute OpenIssues real");
            LinesToWrite.Add("@attribute HasDownloads { TRUE,FALSE}");
            LinesToWrite.Add("@attribute ReleaseCount real");
            LinesToWrite.Add("@attribute isSuccessFull { TRUE,FALSE}");
            LinesToWrite.Add("");
            LinesToWrite.Add("@data");
            string Value = ((ComboBoxItem)LanguageComboBox.SelectedItem).Content.ToString();

            if (((ComboBoxItem)LanguageComboBox.SelectedItem).Content.ToString() == "C#/C++")
            {
                Value = "C";
            }
            LinesToWrite.Add(Value + "," +
                             ContributersTextBox.Text + "," +
                             CommitsTextBox.Text + "," +
                             StarsTextBox.Text + "," +
                             ForksTextBox.Text + "," +
                             BranchesTextBox.Text + "," +
                             WatchersTextBox.Text + "," +
                             PullRequestsTextBox.Text + "," +
                             TotalIssuesTextBox.Text + "," +
                             OpenIssuesTextBox.Text + "," +
                             ((ComboBoxItem)HasDownloadsComboBox.SelectedItem).Content.ToString() + "," +
                             ReleaseCountsTextBox.Text + "," + "?"
                             );
            System.IO.File.WriteAllLines("Dataset.arff", LinesToWrite);
            Classifier cl          = SerializationHelper.read(@"RF.model") as Classifier;
            Instances  testDataSet = new Instances(new java.io.FileReader("Dataset.arff"));

            testDataSet.setClassIndex(testDataSet.numAttributes() - 1);
            Evaluation evaluation = new Evaluation(testDataSet);

            for (int i = 0; i < testDataSet.numInstances(); i++)
            {
                Instance instance = testDataSet.instance(i);
                evaluation.evaluateModelOnceAndRecordPrediction(cl, instance);
            }
            double Prediction = -1;

            foreach (object o in evaluation.predictions().toArray())
            {
                NominalPrediction prediction = o as NominalPrediction;
                if (prediction != null)
                {
                    double[] distribution = prediction.distribution();
                    Prediction = prediction.predicted();
                }
            }
            if (Prediction == -1)
            {
                ResultLabel.Content = "Error Parsing";
            }
            else if (Prediction == 0)
            {
                ResultLabel.Content = "Successfull";
            }
            else
            {
                ResultLabel.Content = "UnSuccessfull";
            }
        }