Example #1
0
        public List <int[]> FrequentItemsets_Apriori(double threshold)
        {
            List <int[]>       itemsets     = context.Items.Select(s => new int[] { s.Value.Code }).ToList();
            List <List <int> > transactions = context.Transactions.Select(t => t.Value.Items).ToList();

            return(Apriori.GenerateAllFrecuentItemsets(itemsets, transactions, threshold).ToList());
        }
Example #2
0
        public List <String> FrequentItemSetsByDepartment(String department, double support)
        {
            List <int[]>       itemsets     = TransactionsByDepartment(department).SelectMany(t => t.Items).Distinct().Select(s => new int[] { s }).ToList();
            List <List <int> > transactions = TransactionsByDepartment(department).Select(t => t.Items).ToList();
            var frequent = Apriori.GenerateAllFrecuentItemsets(itemsets, transactions, support).ToList();

            return(formatItemSets(frequent));
        }
Example #3
0
        public List <String> FrequentItemSetsByClient(String clientCode, double Support)
        {
            List <int[]>       itemsets     = context.Clients[clientCode].Transactions.SelectMany(t => t.Items).Distinct().Select(s => new int[] { s }).ToList();
            List <List <int> > transactions = context.Clients[clientCode].Transactions.Select(t => t.Items).ToList();
            var frequent = Apriori.GenerateAllFrecuentItemsets(itemsets, transactions, Support).ToList();

            return(formatItemSets(frequent));
        }
Example #4
0
 public IEnumerable <String> dependencesbyDepartment(String department, int itemCode, double support)
 {
     try
     {
         List <int[]>       itemsets     = TransactionsByDepartment(department).SelectMany(t => t.Items).Distinct().Select(s => new int[] { s }).ToList();
         List <List <int> > transactions = TransactionsByDepartment(department).Select(t => t.Items).ToList();
         var frequent = Apriori.GenerateAllFrecuentItemsets(itemsets, transactions, support).ToList();
         Rules = new Dictionary <int, List <int[]> >();
         AssociatonRule.GenerateAllRules <int>(frequent, Rules);
         var y = Rules[itemCode];
         return(formatItemSets(y));
     }
     catch
     {
         return(null);
     }
 }
Example #5
0
        public void generateFrecuentItemsets(double threshold, string region)
        {
            TimeSpan stop;
            TimeSpan start = new TimeSpan(DateTime.Now.Ticks);

            if (!region.Equals("TODO"))
            {
                foreach (int t in Transactions.Keys)
                {
                    if (Clients[Transactions[t].ClientCode].Departament.Equals(region))
                    {
                        FilteredTransactions.Add(Transactions[t].Code, Transactions[t]);
                    }
                }
            }
            else
            {
                FilteredTransactions = Transactions;
            }



            if (region.Equals("VALLE DEL CAUCA") || region.Equals("BOGOTA") || region.Equals("CUNDINAMARCA") || region.Equals("RISARALDA") || region.Equals("TODO"))
            {
                PrunningClientsAndTransactions();
            }
            else
            {
                TransactionsPrunned = FilteredTransactions;
            }


            stop = new TimeSpan(DateTime.Now.Ticks);
            Console.WriteLine("Time prunning clients and transactions: " + stop.Subtract(start).TotalSeconds + " segundos");



            List <List <int> > transactions = TransactionsPrunned.Select(t => t.Value.Items).ToList();
            List <int[]>       itemsets     = GenerateItemSet_BruteForce(1);


            List <int[]> frecuentIS = Apriori.GenerateAllFrecuentItemsets(itemsets, transactions, threshold).ToList();

            listadoIF = auxiliarIF(frecuentIS, transactions);

            Console.WriteLine("Number of frecuent itemsets: " + frecuentIS.Count);

            List <Itemset> FIS = new List <Itemset>();

            for (int i = 0; i < frecuentIS.Count; i++)
            {
                int[]       actual   = frecuentIS.ElementAt(i);
                List <Item> theItems = new List <Item>();

                for (int j = 0; j < actual.Length; j++)
                {
                    Item theItem = Items[actual[j]];
                    theItems.Add(theItem);
                }

                double averageP = theItems.Average(it => it.AveragePrice);
                double averageC = theItems.Average(it => Convert.ToDouble(it.Clasification));

                Itemset nuevoItemset = new Itemset(theItems, averageP, averageC);

                FIS.Add(nuevoItemset);
            }

            FrecuentItemsets = FIS;
        }