/// <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); }
/// <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); }