예제 #1
0
        private static void PredictSingle(IMLModelEngine <SampleObservation, SamplePrediction> mlModelScorer)
        {
            // Create sample data to do a single prediction with it
            SampleObservation sampleData = CreateSingleDataSample();

            // Make a single prediction
            var resultprediction = mlModelScorer.Predict(sampleData);

            Console.WriteLine($"=============== Single Prediction  ===============");
            Console.WriteLine($"Actual value: {sampleData.Fare_amount} | Predicted value: {resultprediction.Score}");
            Console.WriteLine($"==================================================");
        }
        public ActionResult <string> PredictSentiment([FromQuery] string sentimentText)
        {
            SampleObservation sampleData = new SampleObservation()
            {
                SentimentText = sentimentText
            };

            //Predict sentiment
            SamplePrediction prediction = _modelEngine.Predict(sampleData);

            bool   isToxic     = prediction.IsToxic;
            float  probability = CalculatePercentage(prediction.Score);
            string retVal      = $"Prediction: Is Toxic?: '{isToxic.ToString()}' with {probability.ToString()}% probability of toxicity  for the text '{sentimentText}'";

            return(retVal);
        }