public ActionResult ReglasDeAsociacion() { var lista = new List <ReglaAsociacion>(); String[] listaWS; listaWS = serviciosWeb.reglasAsociacion(); Char delimiter = '/'; for (int i = 0; i < listaWS.Length; i++) { var regla = new ReglaAsociacion(); String[] substrings = listaWS[i].Split(delimiter); regla.NumeroPremisa = (i + 1).ToString(); regla.Premisa = substrings[0]; regla.Conclusion = substrings[1]; regla.Confianza = substrings[2]; lista.Add(regla); } Session["Producto1"] = lista[0].Premisa.ToString(); Session["Producto2"] = lista[0].Conclusion.ToString(); return(View(lista)); }
public static List <ReglaAsociacion> ReglasAsociacion(List <List <string> > db, List <List <string> > L, double confidenceThreshold) { List <ReglaAsociacion> allRules = new List <ReglaAsociacion>(); foreach (List <string> itemset in L) { var subsets = GetPowerSet(itemset); foreach (var subset in subsets) { double confidence = (FindSupport(itemset, db) / FindSupport(subset.ToList(), db)) * 100.0; if (confidence >= confidenceThreshold) { ReglaAsociacion rule = new ReglaAsociacion(); string[] temp = new string[itemset.Count]; itemset.CopyTo(temp); List <string> itemset2 = temp.ToList(); rule.X.AddRange(subset); subset.ToList().ForEach(x => itemset2.Remove(x)); rule.Y.AddRange(itemset2); rule.Support = FindSupport(itemset, db); rule.Confidence = confidence; if (rule.X.Count > 0 && rule.Y.Count > 0) { allRules.Add(rule); } } } } return(allRules); }
public String convertRules(ReglaAsociacion rule) { String line = ""; var ant = rule.X; var con = rule.Y; ant.ForEach(x => line += listItems.First(p => p.itemCode == Convert.ToInt32(x)).itemName + ","); line += "-"; con.ForEach(y => line += listItems.First(p => p.itemCode == Convert.ToInt32(y)).itemName + ","); return(line); }