private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            TrainingBox.IsChecked   = false;
            PlotBox.IsChecked       = false;
            RestartButton.IsEnabled = false;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();

            // Clear the diagram.
            Diagram.Model.PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1);
            Diagram.InvalidatePlot();

            // Create and train the regression model
            TrainingBox.IsChecked = true;
            var dataPath = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_train.csv");

            var featureImportances = await ViewModel.ComputePermutationMetrics(dataPath);

            // Visualize the R-Squared decrease for the model features.
            PlotBox.IsChecked = true;
            UpdatePlot(featureImportances);

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            RestartButton.IsEnabled = true;
        }
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked    = false;
            SettingUpBox.IsChecked  = false;
            TrainingBox.IsChecked   = false;
            TestingBox.IsChecked    = false;
            PlottingBox.IsChecked   = false;
            RestartButton.IsEnabled = false;
            PredictButton.IsEnabled = false;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();

            // Prepare diagram
            var plotModel = Diagram.Model;

            plotModel.PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1);
            Diagram.InvalidatePlot();

            // Prepare the input files
            DatasetBox.IsChecked = true;
            var testDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/test.tsv");

            // Configure data transformations.
            SettingUpBox.IsChecked = true;
            var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/training.tsv");

            await ViewModel.Build();

            // Create and train the model
            TrainingBox.IsChecked = true;
            await ViewModel.Train(trainingDataPath);

            // Save the model.
            await ViewModel.Save("classificationModel.zip");

            // Test and evaluate the model
            TestingBox.IsChecked = true;
            var metrics = await ViewModel.Evaluate(testDataPath);

            // Diagram
            PlottingBox.IsChecked = true;

            var bars = new List <BarItem>();

            foreach (var logloss in metrics.PerClassLogLoss)
            {
                bars.Add(new BarItem {
                    Value = logloss
                });
            }

            (plotModel.Series[0] as BarSeries).ItemsSource = bars;
            plotModel.InvalidatePlot(true);

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            RestartButton.IsEnabled = true;
            PredictButton.IsEnabled = true;
        }
Ejemplo n.º 3
0
        private async void Calculate_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Votes.Text = string.Empty;

            var testDataLocation = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_test.csv");

            var tests = await ViewModel.GetSample(testDataLocation);

            var size = 50;
            var data = tests.ToList().Take(size);

            var perceptronPrediction         = (await ViewModel.Predict(_perceptronBinaryModel, data)).ToList();
            var linearSvmPrediction          = (await ViewModel.Predict(_linearSvmModel, data)).ToList();
            var logisticRegressionPrediction = (await ViewModel.Predict(_logisticRegressionModel, data)).ToList();
            var sdcabPrediction = (await ViewModel.Predict(_sdcabModel, data)).ToList();

            for (int i = 0; i < size; i++)
            {
                var vote = perceptronPrediction[i].LabelAsNumber +
                           linearSvmPrediction[i].LabelAsNumber +
                           logisticRegressionPrediction[i].LabelAsNumber +
                           sdcabPrediction[i].LabelAsNumber;

                if (vote > 0 && vote < 4)
                {
                    Votes.Text +=
                        i.ToString("000     ") +
                        BoolVisual(perceptronPrediction[i].PredictedLabel) +
                        BoolVisual(linearSvmPrediction[i].PredictedLabel) +
                        BoolVisual(logisticRegressionPrediction[i].PredictedLabel) +
                        BoolVisual(sdcabPrediction[i].PredictedLabel) + Environment.NewLine;
                }
            }
        }
Ejemplo n.º 4
0
        public Task <List <List <double> > > LoadClusteringData()
        {
            return(Task.Run(async() =>
            {
                var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/Mall_Customers.csv");
                var reader = _mlContext.Data.CreateTextLoader(
                    new TextLoader.Options()
                {
                    Separators = new[] { ',' },
                    HasHeader = true,
                    Columns = new[]
                    {
                        new TextLoader.Column("Age", DataKind.Single, 2),
                        new TextLoader.Column("AnnualIncome", DataKind.Single, 3),
                        new TextLoader.Column("SpendingScore", DataKind.Single, 4),
                    }
                });

                var dataView = reader.Load(trainingDataPath);
                var result = new List <List <double> >();
                for (int i = 0; i < dataView.Schema.Count; i++)
                {
                    var column = dataView.Schema[i];
                    result.Add(dataView.GetColumn <float>(column).Select(f => (double)f).ToList());
                }

                return result;
            }));
        }
Ejemplo n.º 5
0
        public Task<List<List<double>>> LoadCorrelationData()
        {
            return Task.Run(async () =>
            {
                var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/titanic.csv");
                var readerOptions = new TextLoader.Options()
                {
                    Separators = new[] { ',' },
                    HasHeader = true,
                    AllowQuoting = true,
                    Columns = new[]
                        {
                        new TextLoader.Column("Survived", DataKind.Single, 1),
                        new TextLoader.Column("PClass", DataKind.Single, 2),
                        new TextLoader.Column("Age", DataKind.Single, 5),
                        new TextLoader.Column("SibSp", DataKind.Single, 6),
                        new TextLoader.Column("Parch", DataKind.Single, 7),
                        new TextLoader.Column("Fare", DataKind.Single, 9)
                        }
                };

                var dataView = _mlContext.Data.LoadFromTextFile(trainingDataPath, readerOptions);
                var result = new List<List<double>>();
                for (int i = 0; i < dataView.Schema.Count; i++)
                {
                    var column = dataView.Schema[i];
                    result.Add(dataView.GetColumn<float>(column).Select(f => (double)f).ToList());
                }

                return result;
            });
        }
Ejemplo n.º 6
0
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Prepare diagram
            var plotModel = PrepareDiagram();

            // Read data
            var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/Mall_Customers.csv");
            var data = await ViewModel.Load(trainingDataPath);

            // Populate diagram
            var ages = new List<double>();
            var incomes = new List<double>();
            var scores = new List<double>();
            foreach (var value in data)
            {
                ages.Add(value.Age);
                incomes.Add(value.AnnualIncome);
                scores.Add(value.SpendingScore);
            }

            AddItem(plotModel, ages, 0);
            AddItem(plotModel, incomes, 1);
            AddItem(plotModel, scores, 2);

            // Update diagram
            Diagram.InvalidatePlot();
        }
Ejemplo n.º 7
0
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked             = false;
            TrainingBox.IsChecked            = false;
            SavingBox.IsChecked              = false;
            TestingBox.IsChecked             = false;
            RestartButton.IsEnabled          = false;
            TravelerTypesCombo.SelectedIndex = -1;
            SeasonsCombo.SelectedIndex       = -1;
            ResultBlock.Text = string.Empty;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();

            // Prepare diagram
            Diagram.Model.PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1);
            Diagram.InvalidatePlot();

            // Prepare the input files
            DatasetBox.IsChecked = true;
            var dataPath = await MlDotNet.FilePath(@"ms-appx:///Data/LasVegasTripAdvisorReviews.csv");

            var data = await ViewModel.Load(dataPath);

            TravelerTypesCombo.ItemsSource = ViewModel.TravelerTypes;
            SeasonsCombo.ItemsSource       = ViewModel.Seasons;
            HotelsCombo.ItemsSource        = ViewModel.Hotels;

            // Create and train the model
            TrainingBox.IsChecked = true;
            await ViewModel.Build();

            // Save the model.
            SavingBox.IsChecked = true;
            await ViewModel.Save("FfmRecommendationModel.zip");

            // Test and evaluate the model
            TestingBox.IsChecked = true;
            var metrics = await ViewModel.Evaluate(dataPath);

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            RestartButton.IsEnabled          = true;
            TravelerTypesCombo.SelectedIndex = 0;
            SeasonsCombo.SelectedIndex       = 0;
        }
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked     = false;
            SettingUpBox.IsChecked   = false;
            TrainingBox.IsChecked    = false;
            CalculatingBox.IsChecked = false;
            PlottingBox.IsChecked    = false;
            PrepareDiagram();

            // Preparing the files.
            DatasetBox.IsChecked = true;
            var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/Mall_Customers.csv");

            // Read training data.
            var trainingDataView = await ViewModel.Load(trainingDataPath);

            // Create the model.
            SettingUpBox.IsChecked = true;
            await ViewModel.Build();

            // Train the model.
            TrainingBox.IsChecked = true;
            await ViewModel.Train(trainingDataView);

            // Save the model.
            await ViewModel.Save("clusteringModel.zip");

            // Run the model on a set of data.
            CalculatingBox.IsChecked = true;
            var predictions = await ViewModel.Predict(trainingDataView);

            // Draw the results.
            PlottingBox.IsChecked = true;
            foreach (var prediction in predictions)
            {
                (Diagram.Model.Series[(int)prediction.PredictedCluster - 1] as ScatterSeries).Points.Add(
                    new ScatterPoint
                    (
                        prediction.SpendingScore,
                        prediction.AnnualIncome
                    ));
            }

            Diagram.InvalidatePlot();
        }
Ejemplo n.º 9
0
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked         = false;
            DataViewBox.IsChecked        = false;
            SetUpExperimentBox.IsChecked = false;
            RunExperimentBox.IsChecked   = false;
            ProgressTextBlock.Text       = string.Empty;
            StartButton.IsEnabled        = false;
            AlgorithmTextBlock.Text      = string.Empty;
            HyperButton.IsEnabled        = false;
            _experimentNumber            = 0;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.PlayAnimation();

            // Prepare diagram.
            PrepareDiagram();

            // Prepare datasets.
            DatasetBox.IsChecked = true;
            _trainingDataPath    = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_train.csv");

            _validationDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_test.csv");

            // Create and load dataview.
            DataViewBox.IsChecked = true;
            await ViewModel.CreateDataViews(_trainingDataPath, _validationDataPath);

            // Set up experiment.
            SetUpExperimentBox.IsChecked = true;
            await ViewModel.SetUpExperiment();

            // Run experiment.
            RunExperimentBox.IsChecked = true;
            ProgressTextBlock.Text     = "Starting";
            AlgorithmTextBlock.Text    = "The winner is " + await ViewModel.RunExperiment() + ". 🏆";

            ProgressTextBlock.Text = string.Empty;

            StartButton.IsEnabled = true;
            HyperButton.IsEnabled = true;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.PauseAnimation();
        }
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            TrainingBox.IsChecked   = false;
            WeightsBox.IsChecked    = false;
            PredictionBox.IsChecked = false;
            RestartButton.IsEnabled = false;
            PredictButton.IsEnabled = false;
            LabelText.Text          = string.Empty;
            ScoreText.Text          = string.Empty;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();

            // Clear the diagram.
            Diagram.Model.PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1);
            Diagram.InvalidatePlot();

            // Create and train the regression model
            TrainingBox.IsChecked = true;
            var dataPath = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_train.csv");

            var featureWeights = await ViewModel.BuildAndTrain(dataPath);

            for (int i = 0; i < 11; i++)
            {
                _featureContributions[i].Weight       = featureWeights[i];
                _featureContributions[i].Contribution = 0;
            }

            // Visualize the feature weights for the model.
            WeightsBox.IsChecked = true;
            Diagram.Model.Series[1].IsVisible = false;
            UpdatePlot();

            // Creating the prediction model
            PredictionBox.IsChecked = true;
            await ViewModel.CreatePredictionModel();

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            RestartButton.IsEnabled = true;
            PredictButton.IsEnabled = true;
        }
Ejemplo n.º 11
0
        public Task <List <List <double> > > LoadRegressionData()
        {
            return(Task.Run(async() =>
            {
                var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/2017-18_NBA_salary.csv");
                var reader = _mlContext.Data.CreateTextLoader(
                    new TextLoader.Options()
                {
                    Separators = new[] { ',' },
                    HasHeader = true,
                    Columns = new[]
                    {
                        new TextLoader.Column("Ts", DataKind.Single, 9),
                        new TextLoader.Column("Orb", DataKind.Single, 12),
                        new TextLoader.Column("Drb", DataKind.Single, 13),
                        new TextLoader.Column("Trb", DataKind.Single, 14),
                        new TextLoader.Column("Ast", DataKind.Single, 15),
                        new TextLoader.Column("Stl", DataKind.Single, 16),
                        new TextLoader.Column("Blk", DataKind.Single, 17),
                        new TextLoader.Column("Tov", DataKind.Single, 18),
                        new TextLoader.Column("Usg", DataKind.Single, 19),
                        new TextLoader.Column("Age", DataKind.Single, 4)
                    }
                });

                var dataView = reader.Load(trainingDataPath);
                var result = new List <List <double> >();
                for (int i = 0; i < dataView.Schema.Count; i++)
                {
                    var column = dataView.Schema[i];
                    result.Add(dataView.GetColumn <float>(column).Select(f => (double)f).ToList());
                }

                return result;
            }));
        }
Ejemplo n.º 12
0
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked            = false;
            PerceptronBox.IsChecked         = false;
            LinearSvmBox.IsChecked          = false;
            LogisticRegressionBox.IsChecked = false;
            SdcaBox.IsChecked = false;

            // Prepare datasets.
            DatasetBox.IsChecked = true;
            var trainingDataLocation = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_train.csv");

            _testDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_test.csv");

            // Prepare diagram.
            PrepareDiagram(out ColumnSeries accuracySeries, out ColumnSeries entropySeries, out ColumnSeries f1ScoreSeries);

            // Perceptron
            PerceptronBox.IsChecked = true;
            _perceptronBinaryModel  = await ViewModel.BuildAndTrain(trainingDataLocation, new AveragedPerceptronBinaryClassifier());

            await ViewModel.Save(_perceptronBinaryModel, "perceptronModel.zip");

            var metrics = await ViewModel.Evaluate(_perceptronBinaryModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.Accuracy
            });
            entropySeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.Entropy
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.F1Score
            });

            // Update diagram
            Diagram.InvalidatePlot();

            //// These raise an exception on System.Diagnostics.Process
            //// 'PlatformNotSupportedException: Retrieving information about local processes is not supported on this platform.'
            ////
            //// var fastForestBinaryModel = new ModelBuilder(trainingDataLocation, new FastForestBinaryClassifier()).BuildAndTrain();
            //// var fastTreeBinaryModel = new ModelBuilder(trainingDataLocation, new FastTreeBinaryClassifier()).BuildAndTrain();

            // Linear SVM
            LinearSvmBox.IsChecked = true;
            _linearSvmModel        = await ViewModel.BuildAndTrain(trainingDataLocation, new LinearSvmBinaryClassifier());

            await ViewModel.Save(_linearSvmModel, "linearSvmModel.zip");

            metrics = await ViewModel.Evaluate(_linearSvmModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.Accuracy
            });
            entropySeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.Entropy
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.F1Score
            });

            // Update diagram
            Diagram.InvalidatePlot();

            // Logistic Regression
            LogisticRegressionBox.IsChecked = true;
            _logisticRegressionModel        = await ViewModel.BuildAndTrain(trainingDataLocation, new LogisticRegressionBinaryClassifier());

            await ViewModel.Save(_logisticRegressionModel, "logisticRegressionModel.zip");

            metrics = await ViewModel.Evaluate(_logisticRegressionModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.Accuracy
            });
            entropySeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.Entropy
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.F1Score
            });

            // Update diagram
            Diagram.InvalidatePlot();

            // Stochastic Dual Coordinate Ascent
            SdcaBox.IsChecked = true;
            _sdcabModel       = await ViewModel.BuildAndTrain(trainingDataLocation, new StochasticDualCoordinateAscentBinaryClassifier());

            await ViewModel.Save(_sdcabModel, "sdcabModel.zip");

            metrics = await ViewModel.Evaluate(_sdcabModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.Accuracy
            });
            entropySeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.Entropy
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.F1Score
            });

            // Update diagram
            Diagram.InvalidatePlot();
        }
Ejemplo n.º 13
0
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked    = false;
            SettingUpBox.IsChecked  = false;
            TrainingBox.IsChecked   = false;
            TestingBox.IsChecked    = false;
            PlottingBox.IsChecked   = false;
            RestartButton.IsEnabled = false;
            DraftSlider.IsEnabled   = false;
            AgeSlider.IsEnabled     = false;
            WinsSlider.IsEnabled    = false;
            BoxSlider.IsEnabled     = false;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();

            // Prepare the input files
            DatasetBox.IsChecked = true;
            var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/2017-18_NBA_salary.csv");

            // Read training data
            var trainingData = await ViewModel.Load(trainingDataPath);

            // Configure data transformations.
            SettingUpBox.IsChecked = true;

            // Create and train the model
            TrainingBox.IsChecked = true;
            await ViewModel.BuildAndTrain();

            // Save the model.
            await ViewModel.Save("regressionModel.zip");

            // Visual evaluation of the model.
            TestingBox.IsChecked = true;
            var predictions = await ViewModel.PredictTrainingData();

            var result = predictions.OrderBy((p) => p.Salary).ToList();

            // Diagram
            PlottingBox.IsChecked = true;
            var foreground = OxyColors.SteelBlue;
            var plotModel  = new PlotModel
            {
                PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1),
                PlotAreaBorderColor     = foreground,
                TextColor         = foreground,
                TitleColor        = foreground,
                SubtitleColor     = foreground,
                LegendPosition    = LegendPosition.TopCenter,
                LegendOrientation = LegendOrientation.Horizontal
            };

            var axisX = new LinearAxis
            {
                Position      = AxisPosition.Bottom,
                Title         = "Test Data",
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            };

            plotModel.Axes.Add(axisX);

            var axisY = new LinearAxis
            {
                Title         = "Salary",
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            };

            plotModel.Axes.Add(axisY);

            var realSeries = new ScatterSeries
            {
                Title      = "Real",
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                MarkerFill = OxyColors.SteelBlue
            };

            plotModel.Series.Add(realSeries);

            var predictedSeries = new ScatterSeries
            {
                Title      = "Predicted",
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                MarkerFill = OxyColors.Firebrick
            };

            plotModel.Series.Add(predictedSeries);

            for (int i = 0; i < result.Count; i++)
            {
                realSeries.Points.Add(new ScatterPoint(i, result[i].Salary));
                predictedSeries.Points.Add(new ScatterPoint(i, result[i].Score));
            }

            // Just to put an entry in the Legend.
            var singlePredictionSeries = new ScatterSeries
            {
                Title      = "Single Prediction",
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                MarkerFill = OxyColors.Green
            };

            plotModel.Series.Add(singlePredictionSeries);

            Diagram.Model = plotModel;

            Slider_ValueChanged(this, null);

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            RestartButton.IsEnabled = true;
            DraftSlider.IsEnabled   = true;
            AgeSlider.IsEnabled     = true;
            WinsSlider.IsEnabled    = true;
            BoxSlider.IsEnabled     = true;
        }
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked            = false;
            PerceptronBox.IsChecked         = false;
            LinearSvmBox.IsChecked          = false;
            LogisticRegressionBox.IsChecked = false;
            SdcaBox.IsChecked         = false;
            StartButton.IsEnabled     = false;
            CalculateButton.IsEnabled = false;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.PlayAnimation();

            // Prepare datasets.
            DatasetBox.IsChecked = true;
            var trainingDataLocation = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_train.csv");

            _testDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/winequality_white_test.csv");

            // Prepare diagram.
            PrepareDiagram(out ColumnSeries accuracySeries, out ColumnSeries areaUnderCurveSeries, out ColumnSeries f1ScoreSeries, out ColumnSeries positiveRecallSeries);

            //// This raises a ArgumentOutOfRangeException because of different Label type expected:
            //// var priorModel = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.Prior());
            //// https://github.com/dotnet/machinelearning/issues/3119

            //// These raise an exception on System.Diagnostics.Process
            //// 'PlatformNotSupportedException: Retrieving information about local processes is not supported on this platform.'
            ////
            //// var fastTreeBinaryModel = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.FastTree());
            //// var fastForestBinaryModel = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.FastForest());
            //// https://github.com/dotnet/machinelearning/issues/2444

            // Perceptron
            PerceptronBox.IsChecked = true;
            _perceptronBinaryModel  = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.AveragedPerceptron());

            await ViewModel.Save(_perceptronBinaryModel, "perceptronModel.zip");

            BinaryClassificationMetrics metrics = await ViewModel.EvaluateNonCalibrated(_perceptronBinaryModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.Accuracy
            });
            areaUnderCurveSeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.AreaUnderRocCurve
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.F1Score
            });
            positiveRecallSeries.Items.Add(new ColumnItem {
                CategoryIndex = 0, Value = metrics.PositiveRecall
            });

            // Update diagram
            Diagram.InvalidatePlot();

            // Linear SVM
            LinearSvmBox.IsChecked = true;
            _linearSvmModel        = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.LinearSvm());

            await ViewModel.Save(_linearSvmModel, "linearSvmModel.zip");

            metrics = await ViewModel.EvaluateNonCalibrated(_linearSvmModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.Accuracy
            });
            areaUnderCurveSeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.AreaUnderRocCurve
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.F1Score
            });
            positiveRecallSeries.Items.Add(new ColumnItem {
                CategoryIndex = 1, Value = metrics.PositiveRecall
            });

            // Update diagram
            Diagram.InvalidatePlot();

            // Logistic Regression
            LogisticRegressionBox.IsChecked = true;
            _logisticRegressionModel        = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.LbfgsLogisticRegression());

            await ViewModel.Save(_logisticRegressionModel, "logisticRegressionModel.zip");

            metrics = await ViewModel.Evaluate(_logisticRegressionModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.Accuracy
            });
            areaUnderCurveSeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.AreaUnderRocCurve
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.F1Score
            });
            positiveRecallSeries.Items.Add(new ColumnItem {
                CategoryIndex = 2, Value = metrics.PositiveRecall
            });

            // Update diagram
            Diagram.InvalidatePlot();

            // Stochastic Dual Coordinate Ascent
            SdcaBox.IsChecked = true;
            _sdcabModel       = await ViewModel.BuildAndTrain(trainingDataLocation, ViewModel.MLContext.BinaryClassification.Trainers.SdcaLogisticRegression());

            await ViewModel.Save(_sdcabModel, "sdcabModel.zip");

            metrics = await ViewModel.Evaluate(_sdcabModel, _testDataPath);

            accuracySeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.Accuracy
            });
            areaUnderCurveSeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.AreaUnderRocCurve
            });
            f1ScoreSeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.F1Score
            });
            positiveRecallSeries.Items.Add(new ColumnItem {
                CategoryIndex = 3, Value = metrics.PositiveRecall
            });

            // Update diagram
            Diagram.InvalidatePlot();

            StartButton.IsEnabled     = true;
            CalculateButton.IsEnabled = true;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.PauseAnimation();
        }
        private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DatasetBox.IsChecked    = false;
            SettingUpBox.IsChecked  = false;
            TrainingBox.IsChecked   = false;
            TestingBox.IsChecked    = false;
            PlottingBox.IsChecked   = false;
            RestartButton.IsEnabled = false;
            PredictButton.IsEnabled = false;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.PlayAnimation();

            // Prepare the input files
            DatasetBox.IsChecked = true;
            var testDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/test.tsv");

            // Configure data transformations.
            SettingUpBox.IsChecked = true;
            var trainingDataPath = await MlDotNet.FilePath(@"ms-appx:///Data/training.tsv");

            await ViewModel.Build(trainingDataPath);

            // Create and train the model
            TrainingBox.IsChecked = true;
            await ViewModel.Train();

            // Save the model.
            await ViewModel.Save("classificationModel.zip");

            // Test and evaluate the model
            TestingBox.IsChecked = true;
            var metrics = await ViewModel.Evaluate(testDataPath);

            // Diagram
            PlottingBox.IsChecked = true;
            var foreground = OxyColors.SteelBlue;
            var plotModel  = new PlotModel
            {
                Subtitle = "Model Quality",
                PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1),
                PlotAreaBorderColor     = foreground,
                TextColor     = foreground,
                TitleColor    = foreground,
                SubtitleColor = foreground
            };

            var bars = new List <BarItem>();

            foreach (var logloss in metrics.PerClassLogLoss)
            {
                bars.Add(new BarItem {
                    Value = logloss
                });
            }

            var barSeries = new BarSeries
            {
                ItemsSource       = bars,
                LabelPlacement    = LabelPlacement.Inside,
                TextColor         = OxyColors.Wheat,
                LabelFormatString = "{0:0.00}",
                FillColor         = OxyColors.Firebrick
            };

            plotModel.Series.Add(barSeries);

            plotModel.Axes.Add(new CategoryAxis
            {
                Position    = AxisPosition.Left,
                Key         = "LogLossAxis",
                ItemsSource = new[]
                {
                    "German",
                    "English",
                    "French",
                    "Italian",
                    "Romanian",
                    "Spanish"
                },
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            });

            var linearAxisX = new LinearAxis
            {
                Position      = AxisPosition.Bottom,
                Title         = "Logarithmic loss per class (lower is better)",
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            };

            plotModel.Axes.Add(linearAxisX);

            Diagram.Model = plotModel;

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.PauseAnimation();
            RestartButton.IsEnabled = true;
            PredictButton.IsEnabled = true;
        }