public void ClassificationModelSelectingEnsembleLearner_Learn_Start_With_3_Models()
        {
            var learners = new IIndexedLearner <ProbabilityPrediction>[]
            {
                new ClassificationDecisionTreeLearner(2),
                new ClassificationDecisionTreeLearner(5),
                new ClassificationDecisionTreeLearner(7),
                new ClassificationDecisionTreeLearner(9),
                new ClassificationDecisionTreeLearner(11),
                new ClassificationDecisionTreeLearner(21),
                new ClassificationDecisionTreeLearner(23),
                new ClassificationDecisionTreeLearner(1),
                new ClassificationDecisionTreeLearner(14),
                new ClassificationDecisionTreeLearner(17),
                new ClassificationDecisionTreeLearner(19),
                new ClassificationDecisionTreeLearner(33)
            };

            var metric            = new LogLossClassificationProbabilityMetric();
            var ensembleStrategy  = new MeanProbabilityClassificationEnsembleStrategy();
            var ensembleSelection = new ForwardSearchClassificationEnsembleSelection(metric, ensembleStrategy, 5, 3, true);

            var sut = new ClassificationModelSelectingEnsembleLearner(learners, new RandomCrossValidation <ProbabilityPrediction>(5, 23),
                                                                      ensembleStrategy, ensembleSelection);

            var(observations, targets) = DataSetUtilities.LoadGlassDataSet();

            var model       = sut.Learn(observations, targets);
            var predictions = model.PredictProbability(observations);

            var actual = metric.Error(targets, predictions);

            Assert.AreEqual(0.55183985816428427, actual, 0.0001);
        }
        public void ClassificationModelSelectingEnsembleLearner_Constructor_CrossValidation_Null()
        {
            var learners          = new IIndexedLearner <ProbabilityPrediction> [4];
            var metric            = new LogLossClassificationProbabilityMetric();
            var ensembleStrategy  = new MeanProbabilityClassificationEnsembleStrategy();
            var ensembleSelection = new ForwardSearchClassificationEnsembleSelection(metric, ensembleStrategy, 5, 1, true);

            var sut = new ClassificationModelSelectingEnsembleLearner(learners, null, ensembleStrategy, ensembleSelection);
        }
        public void ClassificationModelSelectingEnsembleLearner_Constructor_Learners_Null()
        {
            var metric            = new LogLossClassificationProbabilityMetric();
            var ensembleStrategy  = new MeanProbabilityClassificationEnsembleStrategy();
            var ensembleSelection = new ForwardSearchClassificationEnsembleSelection(metric, ensembleStrategy, 5, 1, true);
            var crossValidation   = new RandomCrossValidation <ProbabilityPrediction>(5);

            var sut = new ClassificationModelSelectingEnsembleLearner(null, crossValidation, ensembleStrategy, ensembleSelection);
        }
Exemplo n.º 4
0
        public void ForwardSearchClassificationEnsembleSelection_Constructor_Number_Of_Availible_Models_Lower_Than_Number_Of_Models_To_Select()
        {
            var sut = new ForwardSearchClassificationEnsembleSelection(new LogLossClassificationProbabilityMetric(),
                                                                       new MeanProbabilityClassificationEnsembleStrategy(), 5, 1, true);


            var observations = new ProbabilityPrediction[3][];

            observations.Select(t => new ProbabilityPrediction[10]).ToArray();
            var targets = new double[10];

            sut.Select(observations, targets);
        }
Exemplo n.º 5
0
        public void ForwardSearchClassificationEnsembleSelection_Select_Start_With_2_Models()
        {
            var sut = new ForwardSearchClassificationEnsembleSelection(new LogLossClassificationProbabilityMetric(),
                                                                       new MeanProbabilityClassificationEnsembleStrategy(), 3, 2, true);

            var random = new Random(42);

            var observations = CreateModelPredictions(random);
            var targets      = Enumerable.Range(0, 10).Select(v => (double)random.Next(1)).ToArray();

            var actual   = sut.Select(observations, targets);
            var expected = new int[3] {
                0, 1, 1
            };

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void ClassificationModelSelectingEnsembleLearner_Learn_Indexed()
        {
            var learners = new IIndexedLearner <ProbabilityPrediction>[]
            {
                new ClassificationDecisionTreeLearner(2),
                new ClassificationDecisionTreeLearner(5),
                new ClassificationDecisionTreeLearner(7),
                new ClassificationDecisionTreeLearner(9),
                new ClassificationDecisionTreeLearner(11),
                new ClassificationDecisionTreeLearner(21),
                new ClassificationDecisionTreeLearner(23),
                new ClassificationDecisionTreeLearner(1),
                new ClassificationDecisionTreeLearner(14),
                new ClassificationDecisionTreeLearner(17),
                new ClassificationDecisionTreeLearner(19),
                new ClassificationDecisionTreeLearner(33)
            };

            var metric            = new LogLossClassificationProbabilityMetric();
            var ensembleStrategy  = new MeanProbabilityClassificationEnsembleStrategy();
            var ensembleSelection = new ForwardSearchClassificationEnsembleSelection(metric,
                                                                                     ensembleStrategy, 5, 1, true);

            var sut = new ClassificationModelSelectingEnsembleLearner(learners,
                                                                      new RandomCrossValidation <ProbabilityPrediction>(5, 23),
                                                                      ensembleStrategy, ensembleSelection);

            var(observations, targets) = DataSetUtilities.LoadGlassDataSet();

            var indices = Enumerable.Range(0, 25).ToArray();

            var model       = sut.Learn(observations, targets, indices);
            var predictions = model.PredictProbability(observations);

            var actual = metric.Error(targets, predictions);

            Assert.AreEqual(2.3682546920482164, actual, 0.0001);
        }
        public void ClassificationModelSelectingEnsembleLearner_Learn_Indexed()
        {
            var learners = new IIndexedLearner <ProbabilityPrediction>[]
            {
                new ClassificationDecisionTreeLearner(2),
                new ClassificationDecisionTreeLearner(5),
                new ClassificationDecisionTreeLearner(7),
                new ClassificationDecisionTreeLearner(9),
                new ClassificationDecisionTreeLearner(11),
                new ClassificationDecisionTreeLearner(21),
                new ClassificationDecisionTreeLearner(23),
                new ClassificationDecisionTreeLearner(1),
                new ClassificationDecisionTreeLearner(14),
                new ClassificationDecisionTreeLearner(17),
                new ClassificationDecisionTreeLearner(19),
                new ClassificationDecisionTreeLearner(33)
            };

            var metric            = new LogLossClassificationProbabilityMetric();
            var ensembleStrategy  = new MeanProbabilityClassificationEnsembleStrategy();
            var ensembleSelection = new ForwardSearchClassificationEnsembleSelection(metric, ensembleStrategy, 5, 1, true);

            var sut = new ClassificationModelSelectingEnsembleLearner(learners, new RandomCrossValidation <ProbabilityPrediction>(5, 23),
                                                                      ensembleStrategy, ensembleSelection);

            var parser       = new CsvParser(() => new StringReader(Resources.Glass));
            var observations = parser.EnumerateRows(v => v != "Target").ToF64Matrix();
            var targets      = parser.EnumerateRows("Target").ToF64Vector();
            var indices      = Enumerable.Range(0, 25).ToArray();

            var model       = sut.Learn(observations, targets, indices);
            var predictions = model.PredictProbability(observations);

            var actual = metric.Error(targets, predictions);

            Assert.AreEqual(2.3682546920482164, actual, 0.0001);
        }
Exemplo n.º 8
0
 public void ForwardSearchClassificationEnsembleSelection_Constructor_Number_Of_Models_From_Start_Larger_Than_Number_Of_Models_To_Select()
 {
     var sut = new ForwardSearchClassificationEnsembleSelection(
         new LogLossClassificationProbabilityMetric(),
         new MeanProbabilityClassificationEnsembleStrategy(), 3, 5, true);
 }
Exemplo n.º 9
0
 public void ForwardSearchClassificationEnsembleSelection_Constructor_Number_Of_Models_Too_Low()
 {
     var sut = new ForwardSearchClassificationEnsembleSelection(
         new LogLossClassificationProbabilityMetric(),
         new MeanProbabilityClassificationEnsembleStrategy(), 0, 1, true);
 }
Exemplo n.º 10
0
 public void ForwardSearchClassificationEnsembleSelection_Constructor_EnsembleStratey_Null()
 {
     var sut = new ForwardSearchClassificationEnsembleSelection(
         new LogLossClassificationProbabilityMetric(), null, 5, 1, true);
 }
Exemplo n.º 11
0
 public void ForwardSearchClassificationEnsembleSelection_Constructor_Metric_Null()
 {
     var sut = new ForwardSearchClassificationEnsembleSelection(null,
                                                                new MeanProbabilityClassificationEnsembleStrategy(), 5, 1, true);
 }