예제 #1
0
        double CrossValidate(int folds)
        {
            var(observations, targets) = DataSetUtilities.LoadAptitudeDataSet();

            var sut         = new StratifiedCrossValidation <double>(folds, 42);
            var predictions = sut.CrossValidate(new ClassificationDecisionTreeLearner(), observations, targets);
            var metric      = new TotalErrorClassificationMetric <double>();

            return(metric.Error(targets, predictions));
        }
        double CrossValidate(int folds)
        {
            var targetName = "Pass";
            var parser = new CsvParser(() => new StringReader(Resources.AptitudeData));
            var observations = parser.EnumerateRows(v => !v.Contains(targetName)).ToF64Matrix();
            var targets = parser.EnumerateRows(targetName).ToF64Vector();

            var sut = new StratifiedCrossValidation<double>(folds, 42);
            var predictions = sut.CrossValidate(new ClassificationDecisionTreeLearner(), observations, targets);
            var metric = new TotalErrorClassificationMetric<double>();

            return metric.Error(targets, predictions);
        }
예제 #3
0
        double CrossValidate_Provide_Indices(int folds)
        {
            var(observations, targets) = DataSetUtilities.LoadAptitudeDataSet();

            var sut = new StratifiedCrossValidation <double>(folds, 42);

            var rowsToCrossvalidate = targets.Length / 2;
            var indices             = Enumerable.Range(0, rowsToCrossvalidate).ToArray();
            var predictions         = new double[rowsToCrossvalidate];

            sut.CrossValidate(new ClassificationDecisionTreeLearner(), observations, targets, indices, predictions);
            var metric = new TotalErrorClassificationMetric <double>();

            return(metric.Error(targets.Take(rowsToCrossvalidate).ToArray(), predictions));
        }
        double CrossValidate_Provide_Indices(int folds)
        {
            var targetName = "Pass";
            var parser = new CsvParser(() => new StringReader(Resources.AptitudeData));
            var observations = parser.EnumerateRows(v => !v.Contains(targetName)).ToF64Matrix();
            var targets = parser.EnumerateRows(targetName).ToF64Vector();

            var sut = new StratifiedCrossValidation<double>(folds, 42);

            var rowsToCrossvalidate = targets.Length / 2;
            var indices = Enumerable.Range(0, rowsToCrossvalidate).ToArray();
            var predictions = new double[rowsToCrossvalidate];

            sut.CrossValidate(new ClassificationDecisionTreeLearner(), observations, targets, indices, predictions);
            var metric = new TotalErrorClassificationMetric<double>();

            return metric.Error(targets.Take(rowsToCrossvalidate).ToArray(), predictions);
        }