internal override void EvaluateModel(ITransformer trainedModel)
        {
            var predictions = trainedModel.Transform(testData);
            var metrics     = mlContext.MulticlassClassification.Evaluate(data: predictions, labelColumnName: "Digit", scoreColumnName: "Score");

            _metrics.Measure.Gauge.SetValue(MetricsRegistry.TrainTestRate, MetricsTags.CreateMetricsTags(new string[] { "Network" }, new string[] { nameof(MNIST28Predictor) }), TrainTestDataRate);
            _metrics.Measure.Gauge.SetValue(MetricsRegistry.NetworkEvaluatingResult, MetricsTags.CreateMetricsTags(new string[] { "Network", "Algorithm", "Metric", "TrainTestRate" }, new string[] { nameof(MNIST28Predictor), this.TrainingAlgo.ToString(), "MacroAccuracy", this.TrainTestDataRate.ToString() }), metrics.MacroAccuracy);
        }
Beispiel #2
0
        internal override void EvaluateModel(ITransformer trainedModel)
        {
            var predictions = trainedModel.Transform(testData);
            var metrics     = mlContext.BinaryClassification.Evaluate(data: predictions, labelColumnName: "Label", scoreColumnName: "Score");

            //Logging metrics: Test rate and accuracy
            _metrics.Measure.Gauge.SetValue(MetricsRegistry.TrainTestRate, MetricsTags.CreateMetricsTags(new string[] { "Network" }, new string[] { nameof(BankNotePredictor) }), TrainTestDataRate);
            _metrics.Measure.Gauge.SetValue(MetricsRegistry.NetworkEvaluatingResult, MetricsTags.CreateMetricsTags(new string[] { "Network", "Algorithm", "Metric", "TrainTestRate" }, new string[] { nameof(BankNotePredictor), this.TrainingAlgorithm.ToString(), "Accuracy", this.TrainTestDataRate.ToString() }), metrics.Accuracy);
        }
Beispiel #3
0
 internal override void SaveNetwork(ITransformer trainedModel)
 {
     string[] tags = new string[] {
         this.ToString(),
         this.TrainingAlgo.ToString(),
         "Saving Network"
     };
     using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
     {
         mlContext.Model.Save(trainedModel, trainingData.Schema, networkPath);
     }
 }
Beispiel #4
0
        internal override void EvaluateModel(ITransformer trainedModel)
        {
            string[] tags = new string[] {
                this.ToString(),
                this.TrainingAlgo.ToString(),
                "Evaluating Network"
            };
            IDataView predictions;

            using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
            {
                predictions = trainedModel.Transform(testData);
            }
            var metrics = mlContext.Regression.Evaluate(data: predictions, labelColumnName: "Label", scoreColumnName: "Score");

            _metrics.Measure.Gauge.SetValue(MetricsRegistry.TrainTestRate, MetricsTags.CreateMetricsTags(new string[] { "Network" }, new string[] { nameof(EuroPredictor) }), this.TrainTestDataRate);
            _metrics.Measure.Gauge.SetValue(MetricsRegistry.NetworkEvaluatingResult, MetricsTags.CreateMetricsTags(new string[] { "Network", "Algorithm", "Metric", "TrainTestRate" }, new string[] { nameof(EuroPredictor), this.TrainingAlgo.ToString(), "MeanAbsoluteError", this.TrainTestDataRate.ToString() }), metrics.MeanAbsoluteError);
        }
Beispiel #5
0
        internal override IDataView LoadData(MLContext context, string dataPath)
        {
            IDataView loadedData = null;

            string[] tags = new string[] {
                this.ToString(),
                this.TrainingAlgorithm.ToString(),
                "Loading Data"
            };
            using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
            {
                loadedData = context.Data.LoadFromTextFile <BankNotesInput>(path: dataPath,
                                                                            hasHeader: false,
                                                                            separatorChar: ','
                                                                            );
            }

            return(loadedData);
        }
Beispiel #6
0
        public override void ProcessNetwork()
        {
            MLContext mlContext = new MLContext();

            IDataView dataView = LoadData(mlContext, dataPath);

            TrainTestData allData = mlContext.Data.TrainTestSplit(dataView, testFraction: trainTestDataRate);

            trainingData = allData.TrainSet;
            testData     = allData.TestSet;

            var dataprocessPipeline = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: nameof(EuroDataModel.Value))
                                      //Normalizing data
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev1)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev2)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev3)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev4)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev5)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev6)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev7)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev8)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev9)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev10)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev11)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev12)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev13)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev14)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev15)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev16)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev17)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev18)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev19)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev20)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev21)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev22)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev23)))
                                      .Append(mlContext.Transforms.NormalizeMeanVariance(outputColumnName: nameof(EuroDataModel.DiffPrev24)))
                                      //Concatenating input features
                                      .Append(mlContext.Transforms.Concatenate("Features", nameof(EuroDataModel.DiffPrev1), nameof(EuroDataModel.DiffPrev2), nameof(EuroDataModel.DiffPrev3), nameof(EuroDataModel.DiffPrev4), nameof(EuroDataModel.DiffPrev5),
                                                                               nameof(EuroDataModel.DiffPrev6), nameof(EuroDataModel.DiffPrev7), nameof(EuroDataModel.DiffPrev8), nameof(EuroDataModel.DiffPrev9), nameof(EuroDataModel.DiffPrev10), nameof(EuroDataModel.DiffPrev11), nameof(EuroDataModel.DiffPrev12),
                                                                               nameof(EuroDataModel.DiffPrev13), nameof(EuroDataModel.DiffPrev14), nameof(EuroDataModel.DiffPrev15), nameof(EuroDataModel.DiffPrev16), nameof(EuroDataModel.DiffPrev17), nameof(EuroDataModel.DiffPrev18), nameof(EuroDataModel.DiffPrev19),
                                                                               nameof(EuroDataModel.DiffPrev20), nameof(EuroDataModel.DiffPrev21), nameof(EuroDataModel.DiffPrev22), nameof(EuroDataModel.DiffPrev23), nameof(EuroDataModel.DiffPrev24)));

            //Applying training algorithm
            var trainer          = ApplyRegressionTrainingAlgorithm(mlContext, TrainingAlgo);
            var trainingPipeline = dataprocessPipeline.Append(trainer);

            //Training the model
            string[] tags = new string[] {
                this.ToString(),
                this.TrainingAlgo.ToString(),
                "Training the model"
            };
            using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
            {
                trainedModel = trainingPipeline.Fit(trainingData);
            }

            EvaluateModel(trainedModel);

            SaveNetwork(trainedModel);

            TestSomePredictions();
        }
        public override void ProcessNetwork()
        {
            EstimatorChain <KeyToValueMappingTransformer> pipeline = null;

            try
            {
                IDataView loadedData = null;
                string[]  tags       = new string[] {
                    this.ToString(),
                    this.TrainingAlgo.ToString(),
                    "Loading Data"
                };

                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    loadedData = LoadData(mlContext, DataPath);
                }

                TrainTestData allData = mlContext.Data.TrainTestSplit(loadedData, testFraction: trainTestDataRate);
                trainingData = allData.TrainSet;
                testData     = allData.TestSet;
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not load data: " + e.Message);
            }
            try
            {
                pipeline = ConfigureNetwork();
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not set pipeline: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgo.ToString(),
                    "Training the model"
                };
                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    trainedModel = Train(pipeline);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Training was not successful: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgo.ToString(),
                    "Evaluating Network"
                };
                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    EvaluateModel(trainedModel);
                }
            }

            catch (Exception e)
            {
                MessageBox.Show("Evaluating the model was not successful: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgo.ToString(),
                    "Saving Network"
                };
                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    SaveNetwork(trainedModel);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Saving the network was not successful: " + e.Message);
            }
            try
            {
                TestSomePredictions();
            }
            catch (Exception e)
            {
                MessageBox.Show("Loading and using the network was not successful: " + e.Message);
            }
        }
Beispiel #8
0
        public override void ProcessNetwork()
        {
            EstimatorChain <ITransformer> pipeline = null;

            try
            {
                IDataView dataView = LoadData(mlContext, dataPath);
                AppendTrainingTestDataRate(dataView);
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not load data: " + e.Message);
            }
            try
            {
                pipeline = ConfigureNetwork();
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not set pipeline: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgorithm.ToString(),
                    "Training the model"
                };
                //Measuring and logging training duration
                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    trainedModel = Train(pipeline);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Training was not successful: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgorithm.ToString(),
                    "Evaluating Network"
                };

                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    EvaluateModel(trainedModel);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Evaluating the model was not successful: " + e.Message);
            }
            try
            {
                string[] tags = new string[] {
                    this.ToString(),
                    this.TrainingAlgorithm.ToString(),
                    "Saving Network"
                };

                using (_metrics.Measure.Timer.Time(MetricsRegistry.Timer, MetricsTags.CreateMetricsTags(tags)))
                {
                    SaveNetwork(trainedModel);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Saving the network was not successful: " + e.Message);
            }
            try
            {
                TestSomePredictions();
            }
            catch (Exception e)
            {
                MessageBox.Show("Loading and using the network was not successful: " + e.Message);
            }
        }