DataSharp/Data/Analysis/Apriori.cs
/// <summary>
/// Computes the frequent 1-itemsets from the transactions extracted before.
/// </summary>
/// <returns>The frequent 1-itemsets from the transactions extracted before.</returns>
Computes the frequent 1-itemsets from the transactions extracted before.
Computes the frequent 1 - itemsets from the transactions extracted before .
private Dictionary<SortedSet<string>, int> ComputeFrequentOneItemsets()
        {
            Dictionary<string, int> oneItemsets = new Dictionary<string, int>();
            foreach (SortedSet<string> set in transactions)
            {
                foreach (string s in set)
                {
                    if (!oneItemsets.ContainsKey(s))
                        oneItemsets[s] = 1;
                    else
                        oneItemsets[s]++;
                }
            }
            var extractedOneItemsets =
                from c in oneItemsets
                where c.Value >= minSupportCount
                select new { Key = c.Key, Value = c.Value };
            Dictionary<SortedSet<string>, int> frequentOneItemsets = new Dictionary<SortedSet<string>, int>();
            foreach (var itemset in extractedOneItemsets)
            {
                SortedSet<string> items = new SortedSet<string> { itemset.Key };
                frequentOneItemsets.Add(items, itemset.Value);
            }
            return frequentOneItemsets;
        }
private Dictionary < SortedSet < string > , int > ComputeFrequentOneItemsets ( ) { Dictionary < string , int > oneItemsets = new Dictionary < string , int > ( ) ; foreach ( SortedSet < string > set in transactions ) { foreach ( string s in set ) { if ( ! oneItemsets . ContainsKey ( s ) ) oneItemsets [ s ] = 1 ; else oneItemsets [ s ] ++ ; } } var extractedOneItemsets = from c in oneItemsets where c . Value >= minSupportCount select new { Key = c . Key , Value = c . Value } ; Dictionary < SortedSet < string > , int > frequentOneItemsets = new Dictionary < SortedSet < string > , int > ( ) ; foreach ( var itemset in extractedOneItemsets ) { SortedSet < string > items = new SortedSet < string > { itemset . Key } ; frequentOneItemsets . Add ( items , itemset . Value ) ; } return frequentOneItemsets ; }
Computes the frequent 1-itemsets from the transactions extracted before.
Computes the frequent 1 - itemsets from the transactions extracted before .
// Initialize an empty Dictionary<string, int> instance to count the occurance of every kind of items. // Scan each transaction. // Scan every single item in a transaction. // Add the item to the dictionary when first meet it. // Update the counter otherwise. // Extract all the items with occurance greater than the minimum support count. // This LINQ expression will be explained in the document. // Generate the frequent 1-itemsets and add them to a LinkedList<Sorted<string>>. // Return the frequent 1-itemsets.
The frequent 1-itemsets from the transactions extracted before.
The frequent 1 - itemsets from the transactions extracted before .