Ejemplo n.º 1
0
        /// <summary>
        /// Bias variance analysis calculator for constructing learning curves.
        /// Learning curves can be used to determine if a model has high bias or high variance.
        /// </summary>
        /// <param name="trainingValidationIndexSplitter"></param>
        /// <param name="shuffler">Type of shuffler to use when splitting data</param>
        /// <param name="metric">The error metric used</param>
        /// <param name="samplePercentages">A list of sample percentages determining the
        /// training data used in each point of the learning curve</param>
        /// <param name="numberOfShufflesPrSample">How many times should the data be shuffled pr. calculated point</param>
        public LearningCurvesCalculator(ITrainingTestIndexSplitter <double> trainingValidationIndexSplitter,
                                        IIndexSampler <double> shuffler, IMetric <double, TPrediction> metric, double[] samplePercentages, int numberOfShufflesPrSample = 5)
        {
            if (trainingValidationIndexSplitter == null)
            {
                throw new ArgumentException("trainingValidationIndexSplitter");
            }
            if (shuffler == null)
            {
                throw new ArgumentException("shuffler");
            }
            if (samplePercentages == null)
            {
                throw new ArgumentNullException("samplePercentages");
            }
            if (samplePercentages.Length < 1)
            {
                throw new ArgumentException("SamplePercentages length must be at least 1");
            }
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }
            if (numberOfShufflesPrSample < 1)
            {
                throw new ArgumentNullException("numberOfShufflesPrSample must be at least 1");
            }

            m_trainingValidationIndexSplitter = trainingValidationIndexSplitter;
            m_indexedSampler           = shuffler;
            m_samplePercentages        = samplePercentages;
            m_metric                   = metric;
            m_numberOfShufflesPrSample = numberOfShufflesPrSample;
            m_random                   = new Random(42);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="shuffler">the type of shuffler provided</param>
 /// <param name="trainingPercentage">What percentage of the indices should go to the training set</param>
 public TrainingTestIndexSplitter(IIndexSampler <T> shuffler, double trainingPercentage)
 {
     m_indexSampler = shuffler ?? throw new ArgumentNullException(nameof(shuffler));
     if (trainingPercentage <= 0.0 || trainingPercentage >= 1.0)
     {
         throw new ArgumentException("Training percentage must be larger than 0.0 and smaller than 1.0");
     }
     m_trainingPercentage = trainingPercentage;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Cross validation for evaluating how learning algorithms perform on unseen observations
        /// </summary>
        /// <param name="sampler">Sampling strategy for the provided indices
        /// before they are divided into the provided folds</param>
        /// <param name="crossValidationFolds">Number of folds that should be used for cross validation</param>
        public CrossValidation(IIndexSampler <double> sampler, int crossValidationFolds)
        {
            m_indexedSampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
            if (crossValidationFolds < 1)
            {
                throw new ArgumentException("CrossValidationFolds ");
            }

            m_crossValidationFolds = crossValidationFolds;
        }
        /// <summary>
        /// Cross validation for evaluating how learning algorithms perform on unseen observations
        /// </summary>
        /// <param name="sampler">Sampling strategy for the provided indices
        /// before they are divided into the provided folds</param>
        /// <param name="crossValidationFolds">Number of folds that should be used for cross validation</param>
        public CrossValidation(IIndexSampler <double> sampler, int crossValidationFolds)
        {
            if (sampler == null)
            {
                throw new ArgumentNullException("shuffler");
            }
            if (crossValidationFolds < 1)
            {
                throw new ArgumentException("CrossValidationFolds ");
            }

            m_indexedSampler       = sampler;
            m_crossValidationFolds = crossValidationFolds;
        }