Exemple #1
0
        public async Task Predict()
        {
            var contents         = File.ReadAllText(PredictionModelWrapper.GetFilePath(@"test.csv"));
            var data             = FileUtil.Read(contents);
            var plainClassifiers = new List <KeyValuePair <string, TextClassificationResult> >();

            foreach (var item in data)
            {
                var result = await Matcher.Match(item.Description);

                if (result.Classifier != null)
                {
                    var kvp = new KeyValuePair <string, TextClassificationResult>(item.SubCategory, result);
                    plainClassifiers.Add(kvp);
                }
            }

            var correct    = plainClassifiers.Count(x => x.Key == x.Value.Classifier.SubCategory);
            var over       = (double)plainClassifiers.Count;
            var percentage = correct / over;

            Console.WriteLine(percentage.ToString("P5"));

            percentage.Should().BeGreaterThan(.3, percentage.ToString("P5"));
        }
Exemple #2
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
                                                     HttpRequest req, TraceWriter log)
        {
            var r = new StreamReader(req.Body);

            log.Info("Prediction trigger function started...");
            var content = await r.ReadToEndAsync();

            log.Info(content);

            //if (typeof(Microsoft.ML.Runtime.Data.LoadTransform) == null ||
            //    typeof(Microsoft.ML.Runtime.Learners.LinearClassificationTrainer) == null ||
            //    typeof(Microsoft.ML.Runtime.Internal.CpuMath.SseUtils) == null)
            //{
            //  log.Info("Assemblies are NOT loaded correctly");
            //  return new BadRequestObjectResult("ML model failed to load");
            //}

            var request = JsonConvert.DeserializeObject <PredictionRequest>(content);

            var model = await PredictionModel.ReadAsync <BankStatementLineItem, PredictedLabel>(PredictionModelWrapper.GetModel());

            var predicted = model.Predict(BankStatementLineItem.ToBankStatementLineItem(request));

            //return predicted != null
            //  ? (ActionResult) new OkObjectResult(predicted.SubCategory)
            //  : new BadRequestObjectResult("prediction failed");

            return(new BadRequestObjectResult("no dice"));
        }