Esempio n. 1
0
        /// <summary>
        /// Predicts the results for given PMML and CSV file and serialize the results in a CSV file
        /// </summary>
        public Table PredictResult(Table inputTable, string pmmlPath)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(pmmlPath);

            string[] predictedCategories = null;

            //Predict the value for each record using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                var iris = GetDataObject(inputTable, i);

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(iris, null);

                if (i == 0)
                {
                    //Get the predicted propability fields
                    predictedCategories = predictedResult.GetPredictedCategories();
                    //Initialize the output table
                    InitializeTable(inputTable.RowCount, predictedResult.PredictedField, predictedCategories);
                }

                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedValue;

                for (int j = 1; j <= predictedCategories.Length; j++)
                {
                    outputTable[i, j] = predictedResult.GetPredictedProbability(predictedCategories[j - 1]);
                }
            }

            return(outputTable);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets predicted result of input values as observable collection
        /// </summary>
        /// <param name="inputTable">current page input values</param>
        /// <param name="pageSize">page size</param>
        /// <returns>observable collection of predicted results</returns>
        private ObservableCollection <BusinessObject> PredictResult(Table inputTable, int pageSize)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            //Initialize the output table
            InitializeTable(inputTable.RowCount);

            //Gets the start index of page selected
            int startIndex = sfDataPager.PageIndex * sfDataPager.PageSize;

            //Predict the value for each record using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                //Get input values as dictionary object
                Dictionary <string, object> imports = inputTable.ColumnNames.ToDictionary(column => column, column
                                                                                          => inputTable[i, column]);

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(imports, null);

                //Adds predicted ozone reading values to the collection for visualization
                if (!predictedPriceDetails.ContainsKey((startIndex + i + 1).ToString()))
                {
                    imports.Add("predictedPrice", predictedResult.PredictedDoubleValue);
                    predictedPriceDetails.Add((startIndex + i + 1).ToString(), imports);
                }
                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedValue;
            }
            // Merges the selected page inputs and their output values
            var result = viewModel.MergeTable(inputTable, outputTable, inputDataTable);

            return(result);
        }
Esempio n. 3
0
        public string PredictMethod()
        {
            //image path
            string imagePath = "ms-appx:///PredictiveAnalytics/ShowCase/AuditDemo/Images";

            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(new ViewModel().
                                                               GetPMMLPath("ms-appx:///PredictiveAnalytics/ShowCase/AuditDemo/Data/Audit.pmml"));

            //Create and anonymous type for audit record
            var audit = new
            {
                ID         = 0,
                Age        = AgeTextValue,
                Employment = EmploymentSelectedValue,
                Education  = EducationSelectedValue,
                Marital    = MaritalSelectedValue,
                Occupation = OccupationSelectedValue,
                Income     = IncomeTextValue,
                Sex        = GenderSelectedValue,
                Deductions = DeductionTextValue,
                Hours      = HoursTextValue,
                Accounts   = AccountsSelectedValue,
                Adjustment = 0
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(audit, null);

            //Get predicted category 0 or 1
            string predicted = (predictedResult.PredictedValue != null) ? predictedResult.PredictedValue.ToString() : "-";

            if (predicted.Equals("0"))
            {
                Image img = new Image();
                img.Source = new BitmapImage(new Uri(imagePath + "/thumb_yes.png"));
                ImagePath  = img.Source;
            }
            else
            {
                Image img = new Image();
                img.Source = new BitmapImage(new Uri(imagePath + "/thumb_no.png"));
                ImagePath  = img.Source;
            }

            AuditPredicted = predicted == "0" ? "YES!" : "NO!";
            PredictedText  = predicted == "0" ? "Your audit risk is low." : "Your audit risk is high.";

            return(PredictedText);
        }
Esempio n. 4
0
        protected void Predict_Click(object sender, EventArgs e)
        {
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(Server.MapPath("~/App_Data/Audit.pmml"));

            string age       = Age.Value.ToString();
            string income    = Income.Value.ToString();
            string deduction = Deduction.Value.ToString();
            string hours     = Hours.Value.ToString();

            age       = string.IsNullOrEmpty(age) ? "0" : age;
            income    = string.IsNullOrEmpty(income) ? "0" : income;
            deduction = string.IsNullOrEmpty(deduction) ? "0" : deduction;
            hours     = string.IsNullOrEmpty(hours) ? "0" : hours;

            var audit = new
            {
                ID         = 0,
                Age        = Convert.ToInt32(age),
                Employment = EmploymentCollection.Value,
                Education  = EducationCollection.Value,
                Marital    = MaritalCollection.Value,
                Occupation = OccupationCollection.Value,
                Income     = Convert.ToInt32(income),
                Sex        = GenderCollection.Value,
                Deductions = Convert.ToInt32(deduction),
                Hours      = Convert.ToInt32(hours),
                Accounts   = AccountsCollection.Value,
                Adjustment = 0
            };

            PredictedResult predictedResult = evaluator.GetResult(audit, null);

            string auditPredictedValue = (predictedResult.PredictedValue != null) ? predictedResult.PredictedValue.ToString() : "-";

            imagePath.Visible = true;
            if (auditPredictedValue == "0")
            {
                imagePath.ImageUrl = "../Content/images/thumb_yes.png";
                option.Text        = "YES!";
                text.Text          = "Your audit risk is low.";
            }
            else
            {
                imagePath.ImageUrl = "../Content/images/thumb_no.png";
                option.Text        = "NO!";
                text.Text          = "Your audit risk is high.";
            }
        }
Esempio n. 5
0
        public ActionResult PredictiveAnalyticsFeatures(string PetalLength, string PetalWidth, string SepalLength, string SepalWidth)
        {
            string        pmmlFilePath  = Server.MapPath("~/App_Data/IrisTree.pmml");
            PMMLEvaluator pmmlEvaluator = new PMMLEvaluatorFactory().GetPMMLEvaluatorInstance(pmmlFilePath);
            var           anonymousType = new
            {
                SepalLength = SepalLength,
                SepalWidth  = SepalWidth,
                PetalLength = PetalLength,
                PetalWidth  = PetalWidth,
            };
            PredictedResult predictedResult = pmmlEvaluator.GetResult(anonymousType, null);
            var             result          = predictedResult.PredictedValue;

            ViewBag.value = result;
            return(Content(ViewBag.value));
        }
Esempio n. 6
0
        public void Predicted_Button(object sender, RoutedEventArgs e)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            // Input object as dictionary
            var imports = new
            {
                symboling        = symboling.Text,
                normalizedLosses = normalizedlosses.Text,
                make             = ((ComboBoxItem)MakeCombo.SelectedItem).Content,
                fuelType         = ((ComboBoxItem)FuelTypeCombo.SelectedItem).Content,
                aspiration       = ((ComboBoxItem)AspirationCombo.SelectedItem).Content,
                numOfDoors       = ((ComboBoxItem)DoorsCombo.SelectedItem).Content,
                bodyStyle        = ((ComboBoxItem)BodyStyleCombo.SelectedItem).Content,
                driveWheels      = ((ComboBoxItem)DriveWheelsCombo.SelectedItem).Content,
                engineLocation   = ((ComboBoxItem)EngineLocationCombo.SelectedItem).Content,
                wheelBase        = wheelbase.Text,
                length           = length.Text,
                width            = width.Text,
                height           = height.Text,
                curbWeight       = curbweight.Text,
                engineType       = ((ComboBoxItem)EngineTypeCombo.SelectedItem).Content,
                numOfCylinders   = ((ComboBoxItem)CylinderCombo.SelectedItem).Content,
                engineSize       = enginesize.Text,
                fuelSystem       = ((ComboBoxItem)FuelSystemCombo.SelectedItem).Content,
                bore             = bore.Text,
                stroke           = stroke.Text,
                compressionRatio = compression.Text,
                horsepower       = horsepower.Text,
                peakRpm          = peakrpm.Text,
                cityMpg          = citympg.Text,
                highwayMpg       = highwaympg.Text,
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(imports, null);

            this.PredictedPrice.Text = " Vehicle's Price : " + "\"" + Math.Round(predictedResult.PredictedDoubleValue, 2).ToString() + "\"";

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// Gets predicted result of input values as observable collection
        /// </summary>
        /// <param name="inputTable">current page input values</param>
        /// <param name="pageSize">page size</param>
        /// <returns>observable collection of predicted results</returns>
        private ObservableCollection <BusinessObject> PredictResult(Table inputTable, int pageSize)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            //Initialize the output table
            InitializeTable(inputTable.RowCount);

            //Gets the start index of page selected
            int startIndex = sfDataPager.PageIndex * sfDataPager.PageSize;

            //Predict the value for each record using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                //Get input values as dictionary object
                Dictionary <string, object> iris = inputTable.ColumnNames.ToDictionary(column => column, column
                                                                                       => inputTable[i, column]);

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(iris, null);

                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedValue;

                for (int j = 1; j <= predictedResult.GetPredictedCategories().Length; j++)
                {
                    outputTable[i, j] = predictedResult.GetPredictedProbability(predictedResult.GetPredictedCategories()[j - 1]);
                }

                //Adds predicted species result to the collection for visualization
                if (!predictedSpeciesCollection.ContainsKey((startIndex + i + 1).ToString()))
                {
                    iris.Add("predictedSpecies", predictedResult.PredictedValue);
                    iris.Add("species_Setosa", predictedResult.GetPredictedProbability(predictedResult.GetPredictedCategories()[0]));
                    iris.Add("species_Versicolor", predictedResult.GetPredictedProbability(predictedResult.GetPredictedCategories()[1]));
                    iris.Add("species_Virginica", predictedResult.GetPredictedProbability(predictedResult.GetPredictedCategories()[2]));
                    predictedSpeciesCollection.Add((startIndex + i + 1).ToString(), iris);
                }
            }
            // Merges the selected page inputs and their output values
            var result = viewModel.MergeTable(inputTable, outputTable, inputDataTable);

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Predicts the results for given PMML and CSV file and serialize the results in a CSV file
        /// </summary>
        public Table PredictResult(Table inputTable, string pmmlPath)
        {
            string[]      recommendations          = null;
            string[]      exclusiveRecommendations = null;
            string[]      ruleAssociations         = null;
            List <string> input = null;
            int           index = 0;

            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(pmmlPath);

            for (int i = 0; i < inputTable.ColumnNames.Length; i++)
            {
                if (inputTable.ColumnNames[i].ToLower() == "items")
                {
                    index = i;
                }
            }

            //Predict the recommendations, exclusiveRecommendations and ruleAssociations for each transactions using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                input = inputTable[i, index].ToString().Replace("{", "").Replace("}", "").Split(new char[] { ',' }).ToList();

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(input, null);
                recommendations          = predictedResult.GetRecommendations();
                exclusiveRecommendations = predictedResult.GetExclusiveRecommendations();
                ruleAssociations         = predictedResult.GetRuleAssociations();

                if (i == 0)
                {
                    InitializeTable(inputTable.RowCount);
                }

                outputTable[i, 0] = "[" + string.Join(",", recommendations) + "]";
                outputTable[i, 1] = "[" + string.Join(",", exclusiveRecommendations) + "]";
                outputTable[i, 2] = "[" + string.Join(",", ruleAssociations) + "]";
            }

            return(outputTable);
        }
Esempio n. 9
0
        /// <summary>
        /// Predicts the results for given PMML and CSV file and serialize the results in a CSV file
        /// </summary>
        public Syncfusion.PMML.Table PredictResult(string[] input, string pmmlPath)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(pmmlPath);

            string[] predictedCategories = null;
            int      i = 0;

            foreach (string s in input)
            {
                string[] predictedandInput = s.Split(',');

                string[] inputField = predictedandInput[1].Split(' ');

                var record = new
                {
                    field_0 = inputField[0],
                    field_1 = inputField[1],
                    field_2 = inputField[2],
                    field_3 = inputField[3],
                    field_4 = inputField[4],
                    field_5 = inputField[5],
                    field_6 = inputField[6],
                    field_7 = inputField[7]
                };
                PredictedResult predictedResult = evaluator.GetResult(record, null);

                if (i == 0)
                {
                    //Get the predicted propability fields
                    predictedCategories = predictedResult.GetPredictedCategories();
                    //Initialize the output table
                    InitializeTable(input.Length, predictedCategories);
                }

                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedDoubleValue;
                i++;
            }

            return(outputTable);
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting PMML demo...");

            var predictors = new
            {
                predictor_1 = 0.3,
                predictor_2 = 0.2,
                predictor_3 = 3.2,
                predictor_4 = 1.2
            };

            string fileName = "model.pmml";
            string path     = Path.Combine(Environment.CurrentDirectory, fileName);

            Console.WriteLine("File path " + path);

            PMMLEvaluator PMMLEvaluator = new PMMLEvaluatorFactory().GetPMMLEvaluatorInstance(path);

            PredictedResult predictedResult = PMMLEvaluator.GetResult(predictors, null);
        }
Esempio n. 11
0
        public void Predicted_Button(object sender, RoutedEventArgs e)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            // Input object as dictionary
            var wine = new
            {
                Alcohol         = alcohol.Text,
                Malic           = malic.Text,
                Ash             = ash.Text,
                Alcalinity      = alkalinity.Text,
                Magnesium       = magnesium.Text,
                Phenols         = phenols.Text,
                Flavanoids      = flavanoids.Text,
                Nonflavanoids   = nonflavanoids.Text,
                Proanthocyanins = proanthocyanins.Text,
                Color           = color.Text,
                Hue             = hue.Text,
                Dilution        = dilution.Text,
                Proline         = proline.Text
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(wine, null);

            viewModel.WineCollection = new ObservableCollection <Wine>();
            viewModel.WineCollection.Add(new Wine()
            {
                Type = string.Empty,
                Wine1_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("1")),
                Wine2_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("2")),
                Wine3_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("3"))
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Esempio n. 12
0
        /// <summary>
        /// Gets predicted result of input values as observable collection
        /// </summary>
        /// <param name="inputTable">current page input values</param>
        /// <param name="pageSize">page size</param>
        /// <returns>observable collection of predicted results</returns>
        private ObservableCollection <BusinessObject> PredictResult(Table inputTable, int pageSize)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            //Initialize the output table
            InitializeTable(inputTable.RowCount);

            //Gets the start index of page selected
            int startIndex = sfDataPager.PageIndex * sfDataPager.PageSize;

            //Predict the value for each record using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                //Get input values as dictionary object
                Dictionary <string, object> bfeed = inputTable.ColumnNames.ToDictionary(column => column, column
                                                                                        => inputTable[i, column]);

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(bfeed, null);

                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedValue;
                //Add predicted Survival
                outputTable[i, 1] = predictedResult.GetPredictedProbability("survival");

                //Adds predicted survival time values to the collection for visualization
                if (!predictedSurvivalCollection.ContainsKey((startIndex + i + 1).ToString()))
                {
                    bfeed.Add("CumulativeHazard", predictedResult.PredictedValue);
                    bfeed.Add("Predicted_Survival", predictedResult.GetPredictedProbability("survival"));
                    predictedSurvivalCollection.Add((startIndex + i + 1).ToString(), bfeed);
                }
            }
            // Merges the selected page inputs and their output values
            var result = viewModel.MergeTable(inputTable, outputTable, inputDataTable);

            return(result);
        }
Esempio n. 13
0
        public PartialViewResult Index(int Age, string Income, string Deduction, int Hours, string Accounts, string Employment, string Education, string Sex, string Marital, string Occupation)
        {
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(Server.MapPath("~/App_Data/Audit.pmml"));

            var audit = new
            {
                Age        = Age,
                Employment = Employment,
                Education  = Education,
                Marital    = Marital,
                Occupation = Occupation,
                Income     = Income,
                Sex        = Sex,
                Deductions = Deduction,
                Hours      = Hours,
                Accounts   = Accounts,
            };


            PredictedResult predictedResult = evaluator.GetResult(audit, null);

            var Adjusted = (predictedResult.PredictedValue != null) ? predictedResult.PredictedValue.ToString() : "-";

            if (Adjusted == "0")
            {
                ViewBag.Adjusted = Url.Content("~/Content/images/thumb_yes.png");
                ViewBag.Result   = "YES!";
                ViewBag.Text     = "Your audit risk is low.";
            }
            else
            {
                ViewBag.Adjusted = Url.Content("~/Content/images/thumb_no.png");
                ViewBag.Result   = "NO!";
                ViewBag.Text     = "Your audit risk is high.";
            }

            return(PartialView("AuditResult"));
        }
Esempio n. 14
0
        public Table PredictResult(string[] input, string pmmlPath)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(pmmlPath);

            string[] predictedCategories = null;
            int      i = 0;

            foreach (string s in input)
            {
                string[] words = s.Split(' ');

                var record = new
                {
                    field_0 = words[0],
                    field_1 = words[1],
                    field_2 = words[2]
                };
                PredictedResult predictedResult = evaluator.GetResult(record, null);



                if (i == 0)
                {
                    //Get the predicted propability fields
                    predictedCategories = predictedResult.GetPredictedCategories();
                    //Initialize the output table
                    InitializeTable(input.Length, predictedCategories);
                }

                //Add predicted value
                outputTable[i, 0] = predictedResult.PredictedValue;
                i++;
            }

            return(outputTable);
        }
Esempio n. 15
0
        public void Predicted_Button(object sender, RoutedEventArgs e)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            // Input object as dictionary
            var cars = new
            {
                Mileage     = mileage.Text,
                Cylinder    = ((ComboBoxItem)cylinder.SelectedItem).Content,
                Doors       = ((ComboBoxItem)doors.SelectedItem).Content,
                Cruise      = ((ComboBoxItem)cruise.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Sound       = ((ComboBoxItem)sound.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Leather     = ((ComboBoxItem)leather.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Buick       = ((ComboBoxItem)buick.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Cadillac    = ((ComboBoxItem)cadillac.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Chevy       = ((ComboBoxItem)chevy.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Pontiac     = ((ComboBoxItem)pontiac.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Saab        = ((ComboBoxItem)saab.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                Saturn      = ((ComboBoxItem)saturn.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                convertible = ((ComboBoxItem)convertible.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                coupe       = ((ComboBoxItem)coupe.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                hatchback   = ((ComboBoxItem)hatchback.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                sedan       = ((ComboBoxItem)sedan.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                wagon       = ((ComboBoxItem)wagon.SelectedItem).Content.ToString() == "yes" ? 1 : 0
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(cars, null);

            this.PredictedPrice.Text = "Car's Price : " + "\"" + Math.Round(predictedResult.PredictedDoubleValue, 2).ToString() + "\"";

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Esempio n. 16
0
        public void Predicted_Button(object sender, RoutedEventArgs e)
        {
            //Get PMML Evaluator instance
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

            // Input object as dictionary
            var audit = new
            {
                Age        = age.Text,
                Employment = ((ComboBoxItem)EmploymentCombo.SelectedItem).Content,
                Education  = ((ComboBoxItem)EducationCombo.SelectedItem).Content,
                Marital    = ((ComboBoxItem)MaritalCombo.SelectedItem).Content,
                Occupation = ((ComboBoxItem)OccupationCombo.SelectedItem).Content,
                Income     = income.Text,
                Sex        = ((ComboBoxItem)SexCombo.SelectedItem).Content,
                Deductions = deductions.Text,
                Hours      = hours.Text,
                Accounts   = ((ComboBoxItem)AccountsCombo.SelectedItem).Content,
                Adjustment = adjustment.Text,
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(audit, null);

            viewModel.AuditCollection = new ObservableCollection <Audit>();
            viewModel.AuditCollection.Add(new Audit()
            {
                Status = string.Empty,
                Adjustable_probability    = Convert.ToDouble(predictedResult.GetPredictedProbability("0")),
                NonAdjustable_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("1")),
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Esempio n. 17
0
        public ActionResult Analysis(string city, string title, string familysize)
        {
            string        pmmlFilePath  = Server.MapPath("~/App_Data/train.pmml");
            PMMLEvaluator pmmlEvaluator = new PMMLEvaluatorFactory().GetPMMLEvaluatorInstance(pmmlFilePath);
            var           anonymousType = new
            {
                city       = city,
                title      = title,
                familysize = familysize
            };
            PredictedResult predictedResult = pmmlEvaluator.GetResult(anonymousType, null);
            var             result          = predictedResult.PredictedValue;

            ViewBag.value = result;
            if (ViewBag.value == "0")
            {
                ViewBag.result = "He will not buy";
            }
            else
            {
                ViewBag.result = "He will buy";
            }
            return(Content(ViewBag.result));
        }
Esempio n. 18
0
        private void Transactions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Dictionary <string, decimal> recommendedItems = null;

            //Initializes the collection of recommended items for visualization
            viewModel.RecommendedGroceries = new ObservableCollection <RecommendedGroceries>();
            if ((sender as ComboBox).SelectedIndex != -1)
            {
                //Mobile visualization
                if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
                {
                    PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                              GetPMMLEvaluatorInstance(viewModel.GetPMMLPath(pmmlPath));

                    switch (((ComboBoxItem)(sender as ComboBox).SelectedValue).Content.ToString())
                    {
                    case "1":
                        viewModel.PurchasedItems = "citrus fruit,semi-finished bread";
                        break;

                    case "2":
                        viewModel.PurchasedItems = "tropical fruit,yogurt,coffee";
                        break;

                    case "3":
                        viewModel.PurchasedItems = "pip fruit,yogurt,cream cheese";
                        break;

                    case "4":
                        viewModel.PurchasedItems = "other vegetables,whole milk";
                        break;

                    case "5":
                        viewModel.PurchasedItems = "butter,sugar,fruit/vegetable juice";
                        break;
                    }

                    // Groups list of items for each 'transaction ID' as collection
                    List <string> input = viewModel.PurchasedItems.Split(',').ToList();

                    //Get result
                    PredictedResult predictedResult = evaluator.GetResult(input, null);

                    //Adds Recommended items
                    recommendedItems = ((AssociationModelResult)predictedResult).GetConfidences(RecommendationType.Recommendation);
                }
                else
                {
                    //Gets the start index of page selected
                    int startIndex = sfDataPager.PageIndex * sfDataPager.PageSize;
                    //Adds purchased items for selected transaction
                    viewModel.PurchasedItems = inputDataTable[(startIndex + Transactions.SelectedIndex), 1].ToString().Replace("{", "").
                                               Replace("}", "").Replace(",", ", ");
                    //Adds Recommended items as collection
                    recommendedItems = (Dictionary <string, decimal>)recommendedItemCollection[(startIndex +
                                                                                                Transactions.SelectedIndex + 1).ToString()];
                }
                foreach (var item in recommendedItems)
                {
                    if (!viewModel.PurchasedItems.Contains(item.Key))
                    {
                        //Adds recommended items with its confidence value as item source for visualization
                        viewModel.RecommendedGroceries.Add(new RecommendedGroceries()
                        {
                            Item       = item.Key,
                            Confidence = item.Value
                        });
                    }
                }
            }
        }