Пример #1
0
        private void Train(ExperimentModifier settings)
        {
            var setup = MulticlassExperimentSettingsHelper.SetupExperiment(_mLContext, settings, settings.Paths, settings.ForPrs);

            try
            {
                // Start experiment
                var textLoader = _mLContext.Data.CreateTextLoader(setup.columnInference.TextLoaderOptions);
                var paths      = settings.Paths;

                // train once:
                var experimentResult = MulticlassExperimentHelper.Train(
                    _mLContext, settings.LabelColumnName, setup.experimentSettings, new MulticlassExperimentProgressHandler(), paths, textLoader);

                // train twice
                var refitModel = MulticlassExperimentHelper.Retrain(experimentResult,
                                                                    "refit model",
                                                                    new MultiFileSource(paths.TrainPath, paths.ValidatePath),
                                                                    paths.ValidatePath,
                                                                    paths.FittedModelPath, textLoader, _mLContext);

                // final train:
                refitModel = MulticlassExperimentHelper.Retrain(_mLContext, experimentResult, setup.columnInference, paths);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Пример #2
0
        public static (ColumnInferenceResults columnInference, MulticlassExperimentSettings experimentSettings) SetupExperiment(
            MLContext mlContext, ExperimentModifier st, DataFilePaths paths, bool forPrs)
        {
            var columnInference   = InferColumns(mlContext, paths.TrainPath, st.LabelColumnName);
            var columnInformation = columnInference.ColumnInformation;

            st.ColumnSetup(columnInformation, forPrs);

            var experimentSettings = new MulticlassExperimentSettings();

            st.TrainerSetup(experimentSettings.Trainers);
            experimentSettings.MaxExperimentTimeInSeconds = st.ExperimentTime;

            var cts = new System.Threading.CancellationTokenSource();

            experimentSettings.CancellationToken = cts.Token;

            // Set the cache directory to null.
            // This will cause all models produced by AutoML to be kept in memory
            // instead of written to disk after each run, as AutoML is training.
            // (Please note: for an experiment on a large dataset, opting to keep all
            // models trained by AutoML in memory could cause your system to run out
            // of memory.)
            experimentSettings.CacheDirectory   = new DirectoryInfo(Path.GetTempPath());
            experimentSettings.OptimizingMetric = MulticlassClassificationMetric.MicroAccuracy;
            return(columnInference, experimentSettings);
        }
Пример #3
0
        public void Train(DataFilePaths files, bool forPrs)
        {
            var stopWatch = Stopwatch.StartNew();

            var st = new ExperimentModifier(files, forPrs);

            Train(st);

            stopWatch.Stop();
            Trace.WriteLine($"Done creating model in {stopWatch.ElapsedMilliseconds}ms");
        }