Exemple #1
0
        private void TrainAndEvaluateClassifier(Instances data, Instances testData, double splitStoppingConfidence, bool useGainRatio)
        {
            // learn the tree
            ID3Learner learner = new ID3Learner(splitStoppingConfidence, true, useGainRatio);
            Node decisionTree = learner.Learn(data);

            // output the tree
            File.WriteAllText(
                string.Format("{0}_DTID3_{1}_{2}.txt", Path.GetFileNameWithoutExtension(this.trainingDataFilePath), useGainRatio, splitStoppingConfidence.ToString("0.0000")),
                decisionTree.ToString());

            // evaluate the classifier
            DTClassifier classifier = new DTClassifier(decisionTree);
            AccuracyEvaluator evaluator = new AccuracyEvaluator(classifier);
            double accuracy = evaluator.Evaluate(testData);

            this.reportData.Add(
                string.Format("{0}\t\t\t{1}\t\t{2}{3}", splitStoppingConfidence.ToString("0.0000"), useGainRatio, accuracy.ToString("0.0000"), System.Console.Out.NewLine));
        }
 /// <summary>
 /// Initializes a new instance of the AccuracyEvaluator class.
 /// </summary>
 /// <param name="classifier">classifier to evaluate</param>
 public AccuracyEvaluator(DTClassifier classifier)
 {
     this.classifier = classifier;
 }