Ejemplo n.º 1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="CrossValidationResult&lt;TModel&gt;"/> class.
        /// </summary>
        ///
        /// <param name="owner">The <see cref="CrossValidation{TModel}"/> that is creating this result.</param>
        /// <param name="models">The models created during the cross-validation runs.</param>
        ///
        public CrossValidationResult(CrossValidation <TModel> owner, CrossValidationValues <TModel>[] models)
        {
            double[] trainingValues    = new double[models.Length];
            double[] trainingVariances = new double[models.Length];
            int[]    trainingCount     = new int[models.Length];

            double[] validationValues    = new double[models.Length];
            double[] validationVariances = new double[models.Length];
            int[]    validationCount     = new int[models.Length];

            for (int i = 0; i < models.Length; i++)
            {
                trainingValues[i]    = models[i].TrainingValue;
                trainingVariances[i] = models[i].TrainingVariance;

                validationValues[i]    = models[i].ValidationValue;
                validationVariances[i] = models[i].ValidationVariance;

                owner.GetPartitionSize(i, out trainingCount[i], out validationCount[i]);
            }

            this.Settings   = owner;
            this.Models     = models;
            this.Training   = new CrossValidationStatistics(trainingCount, trainingValues, trainingVariances);
            this.Validation = new CrossValidationStatistics(validationCount, validationValues, validationVariances);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Creates a new k-fold cross-validation algorithm.
        /// </summary>
        ///
        /// <param name="size">The total number of available samples.</param>
        /// <param name="folds">The number of folds, usually denoted as <c>k</c> (default is 10).</param>
        ///
        public CrossValidation(int size, int folds)
        {
            if (folds > size)
            {
                throw new ArgumentException("The number of folds can not exceed the total number of samples in the data set", "folds");
            }

            this.samples = size;
            this.folds   = new int[folds][];

            this.indices = CrossValidation.Splittings(size, folds);

            // Create foldings
            for (int i = 0; i < folds; i++)
            {
                this.folds[i] = indices.Find(x => x == i);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Creates a new k-fold cross-validation algorithm.
        /// </summary>
        ///
        /// <param name="labels">A vector containing class labels.</param>
        /// <param name="classes">The number of different classes in <paramref name="labels"/>.</param>
        /// <param name="folds">The number of folds, usually denoted as <c>k</c> (default is 10).</param>
        ///
        public CrossValidation(int[] labels, int classes, int folds)
        {
            if (folds > labels.Length)
            {
                throw new ArgumentException("The number of folds can not exceed "
                                            + "the total number of samples in the data set", "folds");
            }

            this.samples = labels.Length;
            this.folds   = new int[folds][];

            this.indices = CrossValidation.Splittings(labels, classes, folds);

            // Create foldings
            for (int i = 0; i < folds; i++)
            {
                this.folds[i] = indices.Find(x => x == i);
            }
        }