static ItemsetCollection AprioriCalc(ItemsetCollection db, double supportThreshold) { Itemset I = db.GetUniqueItems(); ItemsetCollection LitemList = new ItemsetCollection(); ItemsetCollection PitemList = new ItemsetCollection(); foreach (string item in I) { PitemList.Add(new Itemset() { item }); } int k = 2; while (PitemList.Count != 0) { LitemList.Clear(); foreach (Itemset index in PitemList) { index.Support = db.FindSupport(index); if (index.Support >= supportThreshold) { LitemList.Add(index); itemList.Add(index); } } PitemList.Clear(); PitemList.AddRange(Bit.FindSubsets(LitemList.GetUniqueItems(), k)); //get k-item subsets k += 1; } return(itemList); }
static List <AssociationRule> Rules(ItemsetCollection db, ItemsetCollection L, double confidenceThreshold) { foreach (Itemset itemset in L) { ItemsetCollection subsets = Bit.FindSubsets(itemset, 0); //get all subsets foreach (Itemset subset in subsets) { double confidence = (db.FindSupport(itemset) / db.FindSupport(subset)) * 100.0; if (confidence >= confidenceThreshold) { AssociationRule rule = new AssociationRule(); rule.X.AddRange(subset); rule.Y.AddRange(itemset.Remove(subset)); rule.Support = db.FindSupport(itemset); rule.Confidence = confidence; if (rule.X.Count > 0 && rule.Y.Count > 0) { allRules.Add(rule); } } } } return(allRules); }