Exemple #1
0
        static void Main(string[] args)
        {
            var apriori = new Apriori();

            var support    = 2;
            var confidence = 0.8;

            var transactions = new[] { "milk~egg~flower", "honey~egg~siroup", "milk~honey~egg~siroup", "honey~siroup", "milk~egg~siroup" };
            var items        = new List <string> {
                "milk", "honey", "egg", "flower", "siroup"
            };

            //var transactions = new[] { "1~3~4", "2~3~5", "1~2~3~5", "2~5", "1~3~5" };
            //var items = new List<string> { "1", "2", "3", "4", "5" };

            var transactionsTest = ReadTransactionsFile();
            var itemsTest        = ReadItemsFile();

            var result = apriori.ProcessTransaction(support, confidence, itemsTest, transactionsTest);

            WriteRules(result.StrongRules);
            WriteFrequent(result.FrequentItems);
            WriteClosest(result.ClosedItemSets);
            WriteMaximal(result.MaximalItemSets);

            Console.WriteLine("Done...");
            Console.Read();
        }
Exemple #2
0
        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);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hi, Thank you for choosing AgentNet. \n\n\nGetting latest transaction data from DB...");
            InititalizeData();
            Console.WriteLine("Following items found :");
            Console.WriteLine(string.Join(",", ItemSets));
            Console.WriteLine("Number of transactions found : " + TransactionSets.Count);
            //Console.WriteLine(string.Join(",", TransactionSets));
            Console.Write("Please enter a minimum support (%) :");
            string minSupportStr = Console.ReadLine();//"50";//Console.ReadLine();

            Console.Write("Please enter a minimum confidence (%) :");
            string minConfidenceStr = Console.ReadLine(); //"80";//Console.ReadLine();

            double minSupport    = double.Parse(minSupportStr) / 100;
            double minConfidence = double.Parse(minConfidenceStr) / 100;

            string[] transactionArray = TransactionSets.ToArray();

            IApriori _apriori = new Apriori();
            Output   output   = _apriori.ProcessTransaction(minSupport, minConfidence, ItemSets, transactionArray);

            Console.WriteLine(string.Join("", output.StrongRules.Select(i => i.X + "-->" + i.Y + "\t" + i.Confidence * 100 + "%\n").ToList()));
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string[] items        = ReadFromFile("items.txt");
            string[] itemsD       = null;       // ReadFromFile("itemsD.txt");
            var      transactions = FileReader.FileReader.ReadFromFile("transactions.txt");

            IApriori  apriori   = new Apriori();
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            var result = apriori.ProcessTransaction(0.4, 0.5, items, transactions, itemsD);

            stopWatch.Stop();
            if (result.ClosedItemSets != null)
            {
                Console.Write("Closed itemsets:");
                foreach (var closedItem in result.ClosedItemSets)
                {
                    Console.Write($"\nKey: {closedItem.Key}\t");
                    Console.WriteLine($"Values: \t");
                    foreach (var value in closedItem.Value)
                    {
                        Console.Write($"{{ key: {value.Key}, value: {value.Value}}}, ");
                    }
                }
            }
            Console.WriteLine("Frequent items:");
            foreach (var frequentItem in result.FrequentItems)
            {
                Console.WriteLine($"Name: { string.Join(" ",frequentItem.Names)}, Support: {frequentItem.Support}");
            }
            if (result.MaximalItemSets != null)
            {
                Console.WriteLine("Maximall itemsets:");
                foreach (var maximalItemSet in result.MaximalItemSets)
                {
                    Console.WriteLine($"{maximalItemSet}");
                }
            }

            Console.WriteLine($"Found {result.StrongRules.Count} strong rules:");
            foreach (var strongRule in result.StrongRules)
            {
                Console.WriteLine($"{{{string.Join(" ", strongRule.X)} -> {string.Join(" ", strongRule.Y)}}}, confidence: {strongRule.Confidence}");
            }
            Console.WriteLine($"Processing time: {stopWatch.Elapsed}");
            Console.WriteLine($"All transactions: {transactions.Length}");
            Console.ReadKey();
        }
Exemple #5
0
        public static void Analyze()
        {
            var dna    = new Apriori();
            var output = dna.ProcessTransaction(.1, .1,
                                                new string[] { "a", "b", "c", "d", "e", "f" }.ToList(),
                                                new string[] { "abc", "abcd", "def", "abe", "ab", "abc", "abd" }
                                                );

            var jsonString = JsonConvert.SerializeObject(
                output, Formatting.Indented,
                new JsonConverter[] { new StringEnumConverter() });

            Console.WriteLine(jsonString);
            Console.ReadKey();
        }