/// <summary>
        /// Learns a model that can map the given inputs to the given outputs.
        /// </summary>
        /// <param name="x">The model inputs.</param>
        /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param>
        /// <param name="weights">The weight of importance for each input-output pair (if supported by the learning algorithm).</param>
        /// <returns>A model that has learned how to produce <paramref name="y" /> given <paramref name="x" />.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Please set the Learner property before calling the Learn(x, y) method.
        /// or
        /// Please set the Learner property before calling the Learn(x, y) method.
        /// </exception>
        public override SplitResult <TModel, TInput, TOutput> Learn(TInput[] x, TOutput[] y, double[] weights = null)
        {
            if (Learner == null)
            {
                throw new InvalidOperationException("Please set the Learner property before calling the Learn(x, y) method.");
            }

            if (Loss == null)
            {
                throw new InvalidOperationException("Please set the Learner property before calling the Learn(x, y) method.");
            }

            int n = x.Length;

            if (this.Indices == null || this.IndicesValidationSet == null || this.IndicesTrainingSet == null)
            {
                this.Indices = CreateValidationSplits(x, y);
                this.IndicesValidationSet = Indices.Find(i => i == 1);
                this.IndicesTrainingSet   = Indices.Find(i => i == 0);
            }
            else
            {
                this.ValidationSetProportion = this.IndicesValidationSet.Length / (double)this.Indices.Length;
            }

            var split = new TrainValDataSplit <TInput, TOutput>(0, x, y, weights, IndicesTrainingSet, IndicesValidationSet);

            SplitResult <TModel, TInput, TOutput> result = LearnSubset(split);

            return(result);
        }
Exemple #2
0
        /// <summary>
        ///   Creates a new split-set validation algorithm.
        /// </summary>
        ///
        /// <param name="size">The total number of available samples.</param>
        /// <param name="proportion">The desired proportion of samples in the training
        /// set in comparison with the testing set.</param>
        ///
        public SplitSetValidation(int size, double proportion)
        {
            this.Proportion   = proportion;
            this.IsStratified = false;
            this.Indices      = Categorical.Random(size, proportion);

            this.ValidationSet = Indices.Find(x => x == 0);
            this.TrainingSet   = Indices.Find(x => x == 1);
        }
        /// <summary>
        ///   Creates a new split-set validation algorithm.
        /// </summary>
        ///
        /// <param name="size">The total number of available samples.</param>
        /// <param name="proportion">The desired proportion of samples in the training
        /// set in comparison with the testing set.</param>
        ///
        public SplitSetValidation(int size, double proportion)
        {
            this.Proportion   = proportion;
            this.IsStratified = false;
            this.Indices      = Accord.Statistics.Tools.RandomGroups(size, proportion);

            this.ValidationSet = Indices.Find(x => x == 0);
            this.TrainingSet   = Indices.Find(x => x == 1);
        }
Exemple #4
0
 public DatabaseIndex Find(Predicate <DatabaseIndex> pred)
 {
     return(Indices.Find(pred));
 }