/// <summary>
        /// Maps Custom Text test example and prediction response
        /// </summary>
        /// <param name="documentText"></param>
        /// <param name="labeledExample"></param>
        /// <param name="predictionResponse"></param>
        /// <param name="modelsDictionary"></param>
        /// <returns>Testing Example model used by nuget</returns>
        public static TestingExample CreateTestExample(string documentText, Example labeledExample, CustomTextPredictionResponse predictionResponse, Dictionary <string, string> modelsDictionary)
        {
            var PredictionData           = MapCutomTextPredictionResponse(predictionResponse);
            PredictionObject groundTruth = MapCustomTextLabeledExample(modelsDictionary, labeledExample);

            return(new TestingExample
            {
                Text = documentText,
                LabeledData = groundTruth,
                PredictedData = PredictionData
            });
        }
        /// <summary>
        /// Map CustomText labeled example
        /// </summary>
        /// <param name="modelsDictionary"></param>
        /// <param name="e"></param>
        /// <returns>PredictionObject used by evaluation nuget</returns>
        private static PredictionObject MapCustomTextLabeledExample(Dictionary <string, string> modelsDictionary, Example e)
        {
            var actualClassNames = e.ClassificationLabels?.Where(c => c.Label == true).Select(c => modelsDictionary[c.ModelId]).ToList();

            actualClassNames = actualClassNames ?? new List <string>();
            var groundTruth = new PredictionObject
            {
                Classification = actualClassNames,
                Entities       = MapCustomTextLabeledEntities(e.MiniDocs, modelsDictionary)
            };

            return(groundTruth);
        }
Exemplo n.º 3
0
        void UpdatePrediction(PredictionObject obj)
        {
            obj.Update();
            ////Day Start////
            Label_Full_Day_Average.Text = obj.GetFullDayAverage().ToString("F8") + " btc";
            Label_Full_Day_Median.Text  = obj.GetFullDayMedian().ToString("F8") + " btc";
            Label_Hour_Day_Average.Text = obj.GetHourDayAverage().ToString("F8") + " btc";
            Label_Hour_Day_Median.Text  = obj.GetHourDayMedian().ToString("F8") + " btc";
            ////Day End////

            ////Week Start////
            Label_Full_Week_Average.Text = obj.GetFullWeekAverage().ToString("F8") + " btc";
            Label_Full_Week_Median.Text  = obj.GetFullWeekMedian().ToString("F8") + " btc";
            Label_Hour_Week_Average.Text = obj.GetHourWeekAverage().ToString("F8") + " btc";
            Label_Hour_Week_Median.Text  = obj.GetHourWeekMedian().ToString("F8") + " btc";
            ////Week End////

            ////Month Start////
            Label_Full_Month_Average.Text = obj.GetFullMonthAverage().ToString("F8") + " btc";
            Label_Full_Month_Median.Text  = obj.GetFullMonthMedian().ToString("F8") + " btc";
            Label_Hour_Month_Average.Text = obj.GetHourMonthAverage().ToString("F8") + " btc";
            Label_Hour_Month_Median.Text  = obj.GetHourMonthMedian().ToString("F8") + " btc";
            ////Month End////
        }
        public static async Task <string> MakePredictionRequest(string ImageUrl, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            string url = "https://uksouth.api.cognitive.microsoft.com/customvision/v3.0/Prediction/1660c786-db2d-4626-b37b-37486b2fe7eb/classify/iterations/Iteration5/image";

            using (var client = new HttpClient())
            {
                // Request headers - replace this example key with your valid Prediction-Key.
                client.DefaultRequestHeaders.Add("Prediction-Key", "<PREDICTION KEY>");

                HttpResponseMessage response;
                byte[] byteData;
                // Request body. Try this sample with a locally stored image.
                using (var webClient = new WebClient())
                {
                    byteData = webClient.DownloadData(ImageUrl);
                }

                using (var content = new ByteArrayContent(byteData))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                    response = await client.PostAsync(url, content);

                    var responseStr = await response.Content.ReadAsStringAsync();

                    PredictionObject rootObject = JsonConvert.DeserializeObject <PredictionObject>(responseStr);

                    var mainTag = rootObject.predictions.First().tagName;
                    foreach (var prediction in rootObject.predictions)
                    {
                        string output = prediction.tagName + "-confidence: " + prediction.probability;
                        //await turnContext.SendActivityAsync(MessageFactory.Text(output), cancellationToken);
                    }
                    return(mainTag);
                }
            }
        }
        public static TheoryData EvaluateModelTestData()
        {
            var predictionData = new PredictionObject
            {
                Classification = new List <string> {
                    "testClass"
                },
                Entities = new List <Entity>()
                {
                    new Entity
                    {
                        Name          = "testEntity",
                        StartPosition = 1,
                        EndPosition   = 20,
                        Children      = new List <Entity>()
                        {
                            new Entity
                            {
                                Name          = "testChildEntity",
                                StartPosition = 4,
                                EndPosition   = 10,
                                Children      = null
                            }
                        }
                    }
                }
            };
            var wrongPrediction = new PredictionObject
            {
                Classification = new List <string> {
                    "wrongClass"
                },
                Entities = new List <Entity>()
                {
                    new Entity
                    {
                        Name          = "wrongEntity",
                        StartPosition = 5,
                        EndPosition   = 8,
                        Children      = new List <Entity>()
                        {
                            new Entity
                            {
                                Name          = "testWrongChildEntity",
                                StartPosition = 4,
                                EndPosition   = 10,
                                Children      = null
                            }
                        }
                    }
                }
            };
            var perfectScore = 1.0;
            var worstScore   = 0.0;

            return(new TheoryData <List <TestingExample>, double, int, int>
            {
                {
                    new List <TestingExample> {
                        new TestingExample
                        {
                            PredictedData = predictionData,
                            LabeledData = predictionData
                        }
                    },
                    perfectScore,
                    2,
                    1
                },
                {
                    new List <TestingExample> {
                        new TestingExample
                        {
                            PredictedData = wrongPrediction,
                            LabeledData = predictionData
                        }
                    },
                    worstScore,
                    4,
                    2
                }
            });
        }