Example #1
0
        /// <summary>
        /// Loads the saved model
        /// Creates a single issue of test data.
        /// Predicts Area based on test data.
        /// Combines test data and predictions for reporting.
        /// Displays the predicted results.
        /// </summary>
        private static void PredictIssue()
        {
            var loadedModel = _mlContext.Model.Load(_modelPath, out var modelInputSchema);

            var singleIssue = new GitHubIssue()
            {
                Title = "Entity Framework crashes", Description = "When connecting to the database, EF is crashing"
            };

            // PredictionEngine is not thread-safe. Use in prototype
            // In production use PredictionEnginePool instead
            _predEngine = _mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(loadedModel);

            var prediction = _predEngine.Predict(singleIssue);

            Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ===============");
        }
Example #2
0
        /// <summary>
        /// Creates the training algorithm class.
        /// Trains the model.
        /// Predicts area based on training data.
        /// Returns the model.
        /// </summary>
        /// <param name="trainingDataView"></param>
        /// <param name="pipeline"></param>
        /// <returns></returns>
        public static async Task <IEstimator <ITransformer> > BuildAndTrainModelAsync(IDataView trainingDataView, IEstimator <ITransformer> pipeline)
        {
            var trainingPipeline = pipeline.Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features"))
                                   .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            _trainedModel = await Task.Run(() => trainingPipeline.Fit(trainingDataView));

            _predEngine = _mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_trainedModel);

            var issue = new GitHubIssue()
            {
                Title       = "WebSockets communication is slow on my machine",
                Description = "The WebSockets communication used under the covers by SignalR looks like it is going slow in my development machine.."
            };

            var prediction = _predEngine.Predict(issue);

            Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ===============");

            return(trainingPipeline);
        }