Example #1
0
        private static void UseModelWithUserInput(string userInput)
        {
            PredictionEngine <FeedbackData, FeedbackPrediction> predictionFunction = _mlContext.Model.CreatePredictionEngine <FeedbackData, FeedbackPrediction>(_trainedModel);
            FeedbackData sampleStatement = new FeedbackData
            {
                FeedbackText = userInput
            };

            var resultPrediction = predictionFunction.Predict(sampleStatement);

            Console.WriteLine();
            Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ===============");

            Console.WriteLine();
            Console.WriteLine($"Prediction: {resultPrediction.PredictedStars}");

            Console.WriteLine("=============== End of Predictions ===============");
            Console.WriteLine();
            Console.WriteLine("Was this prediction correct? (Y/N): ");
            var correctStars      = 0;
            var predictionCorrect = Console.ReadLine();

            if (string.Equals(predictionCorrect.ToUpper(), "N"))
            {
                Console.WriteLine("How many stars should it be? ");
                correctStars = int.Parse(Console.ReadLine());
            }
            else
            {
                correctStars = resultPrediction.PredictedStars;
            }
            File.AppendAllText(_dataPath, userInput + "\t" + correctStars + Environment.NewLine);
        }
Example #2
0
        public static void BuildAndTrainModel(IDataView trainingDataView, IEstimator <ITransformer> pipeline)
        {
            var trainingPipeline = pipeline.Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features"))
                                   .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            _trainedModel = trainingPipeline.Fit(trainingDataView);
            _predEngine   = _mlContext.Model.CreatePredictionEngine <FeedbackData, FeedbackPrediction>(_trainedModel);
            FeedbackData feedback = new FeedbackData()
            {
                FeedbackText = "I love this feedback",
                Stars        = 5
            };

            var prediction = _predEngine.Predict(feedback);

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