Example #1
0
        /// <summary>
        /// Trains the model using the ML components in the pipeline.
        /// </summary>
        public ExtendedPredictionModel Train(IHostEnvironment environment = null)
        {
            if (environment == null)
            {
                using (var env = new ConsoleEnvironment(seed: _seed, conc: _conc))
                    return(Train(env));
            }

            Experiment experiment = environment.CreateExperiment();

            Legacy.ILearningPipelineStep          step            = null;
            List <Legacy.ILearningPipelineLoader> loaders         = new List <Legacy.ILearningPipelineLoader>();
            List <Var <ITransformModel> >         transformModels = new List <Var <ITransformModel> >();
            Var <ITransformModel> lastTransformModel = null;

            foreach (Legacy.ILearningPipelineItem currentItem in this)
            {
                if (currentItem is Legacy.ILearningPipelineLoader loader)
                {
                    loaders.Add(loader);
                }

                step = currentItem.ApplyStep(step, experiment);
                if (step is Legacy.ILearningPipelineDataStep dataStep && dataStep.Model != null)
                {
                    transformModels.Add(dataStep.Model);
                }
        public Legacy.ILearningPipelineStep ApplyStep(Legacy.ILearningPipelineStep previousStep, Experiment experiment)
        {
            if (previousStep != null)
            {
                if (!(previousStep is Legacy.ILearningPipelineDataStep dataStep))
                {
                    throw new InvalidOperationException($"{ nameof(NearestNeighborsMultiClass)} only supports an { nameof(Legacy.ILearningPipelineDataStep)} as an input.");
                }

                TrainingData = dataStep.Data;
            }
            Output output = EntryPointsNearestNeighborsMultiClassHelper.Add(experiment, this);

            return(new NearestNeighborsMultiClassPipelineStep(output));
        }
        public Legacy.ILearningPipelineStep ApplyStep(Legacy.ILearningPipelineStep previousStep, Experiment experiment)
        {
            if (previousStep != null)
            {
                if (!(previousStep is Legacy.ILearningPipelineDataStep dataStep))
                {
                    throw new InvalidOperationException($"{ nameof(PassThrough)} only supports an { nameof(Legacy.ILearningPipelineDataStep)} as an input.");
                }

                Data = dataStep.Data;
            }
            Output output = EntryPointsPassThroughHelper.Add(experiment, this);

            return(new PassThroughPipelineStep(output));
        }