コード例 #1
0
        private PredictionViewModel GetModel(SaleDataInputModel inputModel)
        {
            var displayModel = new PredictionViewModel();

            SetMlDisplayPredictionData(displayModel, inputModel);

            SetFourthDisplayPredictionData(displayModel);

            return(displayModel);
        }
コード例 #2
0
        public ActionResult Create(SaleDataInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                RedirectToAction("Index");
            }

            var model = GetModel(inputModel);

            return(View(model));
        }
コード例 #3
0
        private static void SetMlDisplayPredictionData(PredictionViewModel displayModel, SaleDataInputModel inputModel)
        {
            var uri = Properties.Settings.Default.Uri;
            var key = Properties.Settings.Default.Key;

            var client = new SalesDemandService(uri, key);

            var estimatedSales = new List <double>();

            double[] garlicBreadMay = new double[] { 3, 3, 2, 2, 0, 0, 0 };

            var tempDate = inputModel.StartDate;

            while (tempDate <= inputModel.EndDate)
            {
                var data = new Dictionary <string, string>()
                {
                    { "Locationid", "69" },
                    { "RecipeName", "" },
                    { "PLU", inputModel.PLU }, // "2549"},
                    { "Salesdate", tempDate.ToString() },
                    { "Quantity", "1" },
                    { "NetSalesPrice", "1" },
                    { "CostPrice", "1" },
                    { "Year", tempDate.Year.ToString() },
                    { "Month", tempDate.Month.ToString() },
                    { "Day", tempDate.Day.ToString() },
                    { "WeekDay", "1" },
                    { "YearDay", "1" }
                };

                var task = client.GetPrediction1(data);
                task.Wait();
                var predictionResult = GetScoredLabelsValue(task.Result);
                estimatedSales.Add(predictionResult);

                tempDate = tempDate.AddDays(1);
            }

            displayModel.MeanAbsoluteError = MLMathFormulas.MeanAbsoluteError(garlicBreadMay, estimatedSales.ToArray());
            displayModel.MeanSquaredError  = MLMathFormulas.MeanSquaredError(garlicBreadMay, estimatedSales.ToArray());
            var coeff = MLMathFormulas.CoefficientOfDetermination(garlicBreadMay, estimatedSales.ToArray());

            displayModel.CoefficientOfDetermination =
                //coeff > 0
                //? Math.Round(coeff, 6)
                //:
                estimatedSales.First();
        }