Esempio n. 1
0
        public List <AssociationItem> BestItems(List <string> words)
        {
            Apriori          apriori         = new Apriori();
            AssociationRules associtionRules = new AssociationRules();
            List <Item>      items           = apriori.BuildStartItems(transactions);
            var result = apriori.CalcuateApriori(transactions);
            Dictionary <int, List <Item> > lresultDictionary = BuildLResultItems(apriori.LResultLists);
            var wordItem    = BuildItem(words);
            var wordsLength = wordItem.ItemKeys.Count;

            if (lresultDictionary.ContainsKey(wordsLength))
            {
                List <Item> lresultItemList = lresultDictionary[wordsLength];
                Item        foundItem       = FindItem(wordItem, lresultItemList);
                if (foundItem != null)
                {
                    List <Item> foundItems = new List <Item>()
                    {
                        foundItem
                    };
                    return(associtionRules.CalcuateAssoctionRules(foundItems, items, transactions));
                }
            }
            return(null);
        }
        public void ProcessTransactionTest()
        {
            //Arrange
            IApriori target = new Apriori();

            //Act
            Output actual = target.ProcessTransaction(_minSupport, _minConfidence, _items, _transactions);

            //Assert
            Assert.AreEqual(9, actual.FrequentItems.Count);
            Assert.AreEqual(2, actual.FrequentItems["a"].Support);
            Assert.AreEqual(3, actual.FrequentItems["b"].Support);
            Assert.AreEqual(3, actual.FrequentItems["c"].Support);
            Assert.AreEqual(3, actual.FrequentItems["e"].Support);
            Assert.AreEqual(2, actual.FrequentItems["ac"].Support);
            Assert.AreEqual(2, actual.FrequentItems["bc"].Support);
            Assert.AreEqual(3, actual.FrequentItems["be"].Support);
            Assert.AreEqual(2, actual.FrequentItems["ce"].Support);
            Assert.AreEqual(2, actual.FrequentItems["bce"].Support);

            Assert.AreEqual(2, actual.MaximalItemSets.Count);
            Assert.AreEqual("ac", actual.MaximalItemSets[0]);
            Assert.AreEqual("bce", actual.MaximalItemSets[1]);

            Assert.AreEqual(5, actual.StrongRules.Count);
        }
Esempio n. 3
0
        public void SolveTest()
        {
            //Arrange
            IApriori target = new Apriori();

            //Act
            Output actual = target.Solve(minSupport, minConfidence, items, transactions);

            //Assert
            Assert.AreEqual(9, actual.FrequentItems.Count);
            Assert.AreEqual(2, actual.FrequentItems["a"].Support);
            Assert.AreEqual(3, actual.FrequentItems["b"].Support);
            Assert.AreEqual(3, actual.FrequentItems["c"].Support);
            Assert.AreEqual(3, actual.FrequentItems["e"].Support);
            Assert.AreEqual(2, actual.FrequentItems["ac"].Support);
            Assert.AreEqual(2, actual.FrequentItems["bc"].Support);
            Assert.AreEqual(3, actual.FrequentItems["be"].Support);
            Assert.AreEqual(2, actual.FrequentItems["ce"].Support);
            Assert.AreEqual(2, actual.FrequentItems["bce"].Support);

            Assert.AreEqual(4, actual.ClosedItemSets.Count, "ClosedItemSets calculation is wrong");
            Assert.IsTrue(actual.ClosedItemSets.ContainsKey("c"));
            Assert.IsTrue(actual.ClosedItemSets.ContainsKey("be"));
            Assert.IsTrue(actual.ClosedItemSets.ContainsKey("ac"));
            Assert.IsTrue(actual.ClosedItemSets.ContainsKey("bce"));

            Assert.AreEqual(2, actual.MaximalItemSets.Count);
            Assert.AreEqual("ac", actual.MaximalItemSets[0]);
            Assert.AreEqual("bce", actual.MaximalItemSets[1]);

            Assert.AreEqual(5, actual.StrongRules.Count);
        }
Esempio n. 4
0
        private void btn_Solve_Click(object sender, EventArgs e)
        {
            #region validation
            if (!ValidateInput(txt_Support, true) || !ValidateInput(txt_Confidence, true))
            {
                return;
            }
            if (lv_Transactions.Items.Count <= 0)
            {
                MessageBox.Show("Enter Transactions first", "Apriori", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion

            IApriori Apriori = new Apriori();
            double minSupport = double.Parse(txt_Support.Text) / 100;
            double minConfidence = double.Parse(txt_Confidence.Text) / 100;
            IEnumerable<string> Items = GetItems();
            var ourput = Apriori.Solve(minSupport, minConfidence, Items, transactions);

            frmOutput objfrmOutput = new frmOutput(ourput);
            objfrmOutput.ShowDialog();
        }