示例#1
0
        public static void TestTraining(this IClassifier c)
        {
            if (c.IsTrained)
            {
                throw new Exception("Already trained");
            }

            // IsTrained test
            var examples = GetExamples();
            var test     = examples.SubView(0, (.1 * examples.Count).Rounded());
            var train    = examples.SubView(test.Count, examples.Count - test.Count);

            c.Train(train);
            if (!c.IsTrained)
            {
                throw new Exception("Classifier is trained");
            }

            // accuracy test
            double minAccuracy = 0.6;

            if (c.AccuracyOn(train) < minAccuracy && !(c.GetType() == typeof(DecisionStump) && c.AccuracyOn(train) > 0.5))
            {
                throw new Exception("Training accuracy < " + minAccuracy);
            }
            if (c.AccuracyOn(test) < minAccuracy && c.GetType() != typeof(DecisionStump))
            {
                throw new Exception("Test accuray < " + minAccuracy);
            }
        }
示例#2
0
 /// <summary>
 /// Computes the classifier's error in predicting the set of examples
 /// </summary>
 public static double ErrorOn(this IClassifier classifier, IEnumerable <Example> labeledExamples)
 {
     return(1.0 - classifier.AccuracyOn(labeledExamples));
 }