/// <summary>
        /// Predicts the results for given PMML and CSV file and serialize the results in a CSV file
        /// </summary>
        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);
        }
Beispiel #2
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 tips = new
            {
                sex        = ((ComboBoxItem)SexCombo.SelectedItem).Content,
                smoker     = ((ComboBoxItem)SmokerCombo.SelectedItem).Content,
                day        = ((ComboBoxItem)DayCombo.SelectedItem).Content,
                time       = ((ComboBoxItem)TimeCombo.SelectedItem).Content,
                size       = size.Text,
                total_bill = totalbill.Text
            };

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

            this.PredictedTip.Text = "Tip Amount : " + "\"" + Math.Round(predictedResult.PredictedDoubleValue, 2).ToString() + "\"";

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #3
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);

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

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

                if (i == 0)
                {
                    //Initialize the output table
                    InitializeTable(inputTable.RowCount, predictedResult.PredictedField);
                }

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

            return(outputTable);
        }
Beispiel #4
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 breastcancer = new
            {
                horTh    = ((ComboBoxItem)HorthCombo.SelectedItem).Content,
                age      = age.Text,
                menostat = ((ComboBoxItem)MenostatCombo.SelectedItem).Content,
                tsize    = tsize.Text,
                tgrade   = ((ComboBoxItem)HorthCombo.SelectedItem).Content,
                pnodes   = pnodes.Text,
                progrec  = progrec.Text,
                estrec   = estrec.Text,
                time     = time.Text,
            };

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

            viewModel.BreastCancerCollection = new ObservableCollection <BreastCancer>();
            viewModel.BreastCancerCollection.Add(new BreastCancer()
            {
                Status = string.Empty,
                Censored_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("0")),
                Event_probability    = Convert.ToDouble(predictedResult.GetPredictedProbability("1"))
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #5
0
        public void Tip(
            string league,
            int round)
        {
            Predictions.Clear();
            var sched = Context.LeagueSchedule[league][round];

            foreach (var game in sched)
            {
                var prediction = new PredictedResult(game);
                //  just uses table position to predict
                var homeRank = GetRank(game.HomeTeam);
                var awayRank = GetRank(game.AwayTeam);
                if (homeRank < awayRank)
                {
                    prediction.HomeWin = true;
                    prediction.AwayWin = false;
                }
                else
                {
                    prediction.HomeWin = false;
                    prediction.AwayWin = true;
                }
                Predictions.Add(prediction);
            }
        }
Beispiel #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 ozone = new
            {
                Month                      = month.Text,
                Day_of_month               = dayofmonth.Text,
                Day_of_week                = dayofweek.Text,
                pressure_height            = pressureheight.Text,
                Wind_speed                 = windspeed.Text,
                Humidity                   = humidity.Text,
                Temperature_at_Sandburg    = temperatureatsandburg.Text,
                Temperature_at_El_Monte    = temperartureatelmonte.Text,
                Inversion_base_height      = inversionbaseheight.Text,
                Pressure_gradient          = pressuregradient.Text,
                Inversion_base_temperature = inversionbasetemperature.Text,
                Visibility                 = visibility.Text
            };

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

            this.PredictedReading.Text = "Ozone Reading : " + "\"" + Math.Round(predictedResult.PredictedDoubleValue, 2).ToString() + "\"";

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
            this.ResultGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Beispiel #7
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 bfeed = new
            {
                duration = duration.Text,
                delta    = ((ComboBoxItem)delta.SelectedItem).Content.ToString() == "completed" ? 1 : 0,
                race     = ((ComboBoxItem)race.SelectedItem).Content.ToString() == "black" ? 2 : ((ComboBoxItem)race.SelectedItem).Content.ToString() == "white" ? 1 : 0,
                poverty  = ((ComboBoxItem)poverty.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                smoke    = ((ComboBoxItem)smoke.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                alcohol  = ((ComboBoxItem)alcohol.SelectedItem).Content.ToString() == "yes" ? 1 : 0,
                agemth   = agemth.Text,
                ybirth   = ybirth.Text,
                pc3mth   = ((ComboBoxItem)pc3mth.SelectedItem).Content,
                yschool  = yschool.Text
            };

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

            viewModel.BfeedCollection = new ObservableCollection <Bfeed>();
            viewModel.BfeedCollection.Add(new Bfeed()
            {
                Observation        = string.Empty,
                Predicted_Survival = Convert.ToDouble(predictedResult.GetPredictedProbability("survival"))
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #8
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 titanic = new
            {
                pclass = ((ComboBoxItem)PclassCombo.SelectedItem).Content,
                parch  = parch.Text,
                sex    = ((ComboBoxItem)GenderCombo.SelectedItem).Content,
                sibsp  = sibsp.Text,
                age    = age.Text
            };

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

            viewModel.TitanicCollection = new ObservableCollection <Titanic>();
            viewModel.TitanicCollection.Add(new Titanic()
            {
                Status               = string.Empty,
                Died_probability     = Convert.ToDouble(predictedResult.GetPredictedProbability("died")),
                Survived_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("survived"))
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #9
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
            Dictionary <string, object> glass = new Dictionary <string, object>();

            glass.Add("RI", ri.Text);
            glass.Add("Na", na.Text);
            glass.Add("Mg", mg.Text);
            glass.Add("Al", al.Text);
            glass.Add("Si", si.Text);
            glass.Add("K", k.Text);
            glass.Add("Ca", ca.Text);
            glass.Add("Ba", ba.Text);
            glass.Add("Fe", fe.Text);

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

            glass.Add("predictedCluster", predictedResult.PredictedValue);
            this.PredictedPrice.Text = "Predicted Group : \"Cluster" + predictedResult.PredictedValue + "\"";

            //Binds output result for visualization
            BindOutputResults(glass);

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #10
0
        private void button_Click(object sender, EventArgs e)
        {
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(new PMMLDocument(new MemoryStream(Encoding.ASCII.GetBytes(File.ReadAllText("Data/Audit.pmml")))));

            //Create and anonymous type for audit record
            var audit = new
            {
                ID         = 0,
                Age        = AgeTextValue.Text.Trim() != "" ? AgeTextValue.Text : "20",
                Employment = EmploymentCollection.SelectedItem,
                Education  = EducationCollection.SelectedItem,
                Marital    = MaritalCollection.SelectedItem,
                Occupation = OccupationCollection.SelectedItem,
                Income     = IncomeTextValue.Text.Trim() != "" ? IncomeTextValue.Text.ToString() : "20000",
                Sex        = GenderCollection.SelectedItem,
                Deductions = DeductionTextValue.Text.Trim() != "" ? DeductionTextValue.Text.ToString() : "10000",
                Hours      = HoursTextValue.Text.Trim() != "" ? HoursTextValue.Text.ToString() : "12",
                Accounts   = AccountsCollection.SelectedItem,
                Adjustment = 0
            };

            //Get predicted result
            PredictedResult predictedResult = evaluator.GetResult(audit, null);
            //Get predicted category 0 or 1
            string auditPredicted = (predictedResult.PredictedValue != null) ? predictedResult.PredictedValue.ToString() : "-";

            // Display result based on predicted category
            thumb.Image         = auditPredicted == "0" ? Image.FromFile("Images/thumb_yes.png") : Image.FromFile("Images/thumb_no.png");
            AuditPredicted.Text = auditPredicted == "0" ? "YES!" : "NO!";
            PredictedText.Text  = auditPredicted == "0" ? "Your audit risk is low." : "Your audit risk is high.";
        }
        /// <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);
        }
Beispiel #12
0
        private void PredictMethod(object param)
        {
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance("../../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() : "-";

            //Display result based on predicted category
            ImagePath      = predicted == "0" ? "/Images/thumb_yes.png" : "/Images/thumb_no.png";
            AuditPredicted = predicted == "0" ? "YES!" : "NO!";
            PredictedText  = predicted == "0" ? "Your audit risk is low." : "Your audit risk is high.";
        }
        /// <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 glass = GetDataObject(inputTable, i);

                //Get result
                PredictedResult predictedResult = evaluator.GetResult(glass, 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);
        }
Beispiel #14
0
        private void PredictMethod(object param)
        {
            PMMLEvaluator evaluator = new PMMLEvaluatorFactory().
                                      GetPMMLEvaluatorInstance(new PMMLDocument(new MemoryStream(Encoding.ASCII.GetBytes(File.ReadAllText("Assets/AuditShowcase/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() : "-";

            //Display result based on predicted category
            ImagePath      = predicted == "0" ? "/syncfusion.auditshowcase.wpf;component/Assets/AuditShowcase/thumb_yes.png" : "/syncfusion.auditshowcase.wpf;component/Assets/AuditShowcase/thumb_no.png";
            AuditPredicted = predicted == "0" ? "YES!" : "NO!";
            PredictedText  = predicted == "0" ? "Your audit risk is low." : "Your audit risk is high.";
        }
Beispiel #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 iris = new
            {
                Sepal_Length = sepallength.Text,
                Sepal_Width  = sepalwidth.Text,
                Petal_Length = petallength.Text,
                Petal_Width  = petalwidth.Text
            };

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

            viewModel.IrisCollection = new ObservableCollection <Iris>();
            viewModel.IrisCollection.Add(new Iris()
            {
                Species                = string.Empty,
                Setosa_probability     = Convert.ToDouble(predictedResult.GetPredictedProbability("setosa")),
                Versicolor_probability = Convert.ToDouble(predictedResult.GetPredictedProbability("versicolor")),
                Virginica_probability  = Convert.ToDouble(predictedResult.GetPredictedProbability("virginica"))
            });

            //Change of visibility over input and resultant grid
            this.InputGrid.Visibility  = Visibility.Collapsed;
            this.ResultGrid.Visibility = Visibility.Visible;
        }
Beispiel #16
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);

            //Predict the recommendations, exclusiveRecommendations and ruleAssociations for each transactions using the PMML Evaluator instance
            for (int i = 0; i < inputTable.RowCount; i++)
            {
                // Groups list of items for each 'transaction ID' as collection
                List <string> input = inputTable[i, 1].ToString().Replace("{", "").Replace("}", "").Split(new char[] { ',' }).ToList();

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

                //Get recommended items with their confidences and here it is added to collection for visualization
                if (!recommendedItemCollection.ContainsKey(inputTable[i, 0].ToString()))
                {
                    recommendedItemCollection.Add(inputTable[i, 0].ToString(), ((AssociationModelResult)predictedResult).GetConfidences(RecommendationType.Recommendation));
                }

                // Binds recommended items array in the following format to display it in the grid
                outputTable[i, 0] = "[" + string.Join(",", predictedResult.GetRecommendations()) + "]";
                outputTable[i, 1] = "[" + string.Join(",", predictedResult.GetExclusiveRecommendations()) + "]";
                outputTable[i, 2] = "[" + string.Join(",", predictedResult.GetRuleAssociations()) + "]";
            }
            // Merges the selected page inputs and their output values
            var result = viewModel.MergeTable(inputTable, outputTable, inputDataTable);

            return(result);
        }
Beispiel #17
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);
        }
Beispiel #18
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.";
            }
        }
Beispiel #19
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));
        }
        /// <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);
        }
Beispiel #21
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;
        }
Beispiel #22
0
        public PredictedResult Tip(
            Game g)
        {
            var result = new PredictedResult(g);

            var homeOff = Ratings[g.HomeTeam].Offence;
            var homeDef = Ratings[g.HomeTeam].Defence;
            var awayOff = Ratings[g.AwayTeam].Offence;
            var awayDef = Ratings[g.AwayTeam].Defence;

            var homeScore = AverageScore + ((homeOff + awayDef) / 2);
            var awayScore = AverageScore + ((awayOff + homeDef) / 2);

            result.HomeScore = MaxMin((int)homeScore);
            result.AwayScore = MaxMin((int)awayScore);

            return(result);
        }
Beispiel #23
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);
        }
Beispiel #24
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);
        }
Beispiel #25
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);
        }
Beispiel #26
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);
        }
Beispiel #27
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;
        }
Beispiel #28
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"));
        }
Beispiel #29
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;
        }
Beispiel #30
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;
        }