Пример #1
0
        /// <summary>
        /// deploy and predict with loaded model
        /// </summary>
        private static void PredictIssue()
        {
            ITransformer loadedModel;

            using (var stream = new FileStream(_modelPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                loadedModel = _mlContext.Model.Load(stream);
            }
            GitHubIssue singleIssue = new GitHubIssue()
            {
                Title = "Entity Framework crashes", Description = "When connecting to the database, EF is crashing"
            };

            _predEngine = loadedModel.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_mlContext);
            var prediction = _predEngine.Predict(singleIssue);

            Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ===============");
        }
Пример #2
0
        public static IEstimator <ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator <ITransformer> pipeline)
        {
            // choose the lerarning algorithm
            var trainingPipeline = pipeline.Append(_mlContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(DefaultColumnNames.Label, DefaultColumnNames.Features))
                                   .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            // trains the pipeline
            _trainedModel = trainingPipeline.Fit(trainingDataView);
            _predEngine   = _trainedModel.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_mlContext);
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "WebSockets communication is slow in my machine",
                Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.."
            };
            var prediction = _predEngine.Predict(issue);

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