Exemple #1
0
        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);
        }
Exemple #2
0
        public static ItemsetCollection FindSubsets(Itemset itemset, int n)
        {
            ItemsetCollection subsets = new ItemsetCollection();

            int subsetCount = (int)Math.Pow(2, itemset.Count);

            for (int i = 0; i < subsetCount; i++)
            {
                if (n == 0 || GetOnCount(i, itemset.Count) == n)
                {
                    string binary = DecimalToBinary(i, itemset.Count);

                    Itemset subset = new Itemset();
                    for (int charIndex = 0; charIndex < binary.Length; charIndex++)
                    {
                        if (binary[charIndex] == '1')
                        {
                            subset.Add(itemset[charIndex]);
                        }
                    }
                    subsets.Add(subset);
                }
            }

            return(subsets);
        }
Exemple #3
0
        static void DisplayItemSet(ItemsetCollection itemlist, List <AssociationRule> rule)
        {
            Console.WriteLine("Below is the Following: ItemSet using support of " + support + "%");
            foreach (Itemset c in itemlist)
            {
                Console.Write(c.ToString() + " ,");
            }

            Console.WriteLine("\nBelow is the Following: ItemSet using confidence of " + confidence + "%");

            foreach (AssociationRule c in rule)
            {
                Console.Write(c.ToString() + " ,");
            }

            Console.WriteLine("\n<Press Enter>");
            Console.ReadLine();
        }
Exemple #4
0
 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);
 }
Exemple #5
0
        public ItemsetCollection setData()
        {
            _items = new Itemset();
            _items.Add("Game");
            _items.Add("Water");
            _items.Add("Monster");
            _items.Add("Candy");
            _items.Add("Shoes");
            _items.Add("Controller");
            _items.Add("PizzaRolls");
            _items.Add("Console");

            _db = new ItemsetCollection();
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[3], _items[5]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[4]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[2], _items[6]
            });
            _db.Add(new Itemset()
            {
                _items[1], _items[3], _items[4], _items[7]
            });
            _db.Add(new Itemset()
            {
                _items[0], _items[1], _items[6]
            });

            return(_db);
        }