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;
        }
        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;
        }
Ejemplo n.º 3
0
        private async void HyperParametrisation_Clicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
            BusyIndicator.Resume();
            StartButton.IsEnabled = false;
            HyperButton.IsEnabled = false;
            _experimentNumber     = 0;
            PrepareDiagram();
            await ViewModel.HyperParameterize();

            BusyIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            BusyIndicator.Pause();
            StartButton.IsEnabled = true;
            HyperButton.IsEnabled = true;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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.Resume();

            // 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.Pause();
        }
        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.º 7
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;
        }
Ejemplo n.º 8
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;
            StartButton.IsEnabled     = false;
            CalculateButton.IsEnabled = false;

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

            // 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.Pause();
        }