Exemple #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();
        }
Exemple #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();
        }