public void TestSmallSample5Fold()
        {
            var stratifiedKFoldCrossValidation =
                new StratifiedKFoldCrossValidation <string>(smallSample, 5, 1);

            string[] expected2 = { "7", "9", "20", "26", "16", "22" };
            Assert.AreEqual(expected2, stratifiedKFoldCrossValidation.GetTestFold(0).ToArray());
        }
        public void TestSmallSample2Fold()
        {
            var stratifiedKFoldCrossValidation =
                new StratifiedKFoldCrossValidation <string>(smallSample, 2, 1);

            string[] expected3 = { "7", "9", "5", "2", "10", "20", "26", "16", "22", "14", "27", "25", "28", "29", "11" };
            Assert.AreEqual(expected3, stratifiedKFoldCrossValidation.GetTestFold(0).ToArray());
        }
        /**
         * <summary> Execute Stratified Single K-fold cross-validation with the given classifier on the given data set using the given parameters.</summary>
         *
         * <param name="experiment">Experiment to be run.</param>
         * <returns>A Performance instance.</returns>
         */
        public Performance.Performance Execute(Experiment experiment)
        {
            var crossValidation =
                new StratifiedKFoldCrossValidation <Instance.Instance>(experiment.GetDataSet().GetClassInstances(), _k,
                                                                       experiment.GetParameter().GetSeed());
            var trainSet = new InstanceList.InstanceList(crossValidation.GetTrainFold(0));
            var testSet  = new InstanceList.InstanceList(crossValidation.GetTestFold(0));

            return(experiment.GetClassifier().SingleRun(experiment.GetParameter(), trainSet, testSet));
        }
        public void TestLargeSample10Fold()
        {
            var stratifiedKFoldCrossValidation =
                new StratifiedKFoldCrossValidation <int>(largeSample, 10, 1);

            for (var i = 0; i < 10; i++)
            {
                var items     = new HashSet <int>();
                var trainFold = stratifiedKFoldCrossValidation.GetTrainFold(i);
                var testFold  = stratifiedKFoldCrossValidation.GetTestFold(i);
                items.UnionWith(trainFold);
                items.UnionWith(testFold);
                Assert.AreEqual(900, testFold.Count);
                Assert.AreEqual(8100, trainFold.Count);
                Assert.AreEqual(9000, items.Count);
                var trainCounts = new int[3];
                foreach (var integer in trainFold)
                {
                    if (integer < 1000)
                    {
                        trainCounts[0]++;
                    }
                    else
                    {
                        if (integer < 4000)
                        {
                            trainCounts[1]++;
                        }
                        else
                        {
                            trainCounts[2]++;
                        }
                    }
                }
                Assert.AreEqual(900, trainCounts[0]);
                Assert.AreEqual(2700, trainCounts[1]);
                Assert.AreEqual(4500, trainCounts[2]);
                var testCounts = new int[3];
                foreach (var integer in testFold)
                {
                    if (integer < 1000)
                    {
                        testCounts[0]++;
                    }
                    else
                    {
                        if (integer < 4000)
                        {
                            testCounts[1]++;
                        }
                        else
                        {
                            testCounts[2]++;
                        }
                    }
                }
                Assert.AreEqual(100, testCounts[0]);
                Assert.AreEqual(300, testCounts[1]);
                Assert.AreEqual(500, testCounts[2]);
            }
        }