cs-pattern-discovery 1.0.1

Pattern Discovery Algorithms such as Apriori and FP-Growth

Install-Package cs-pattern-discovery -Version 1.0.1
dotnet add package cs-pattern-discovery --version 1.0.1
<PackageReference Include="cs-pattern-discovery" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add cs-pattern-discovery --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

cs-pattern-discovery

Pattern Discovery implemented in C#

Usage

Apriori

The sample codes shows how to use Apriori to find the frequent item sets from a transaction database:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTApriori
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('a', 'c', 'd', 'e') { ID = 10 });
            database.Add(new Transaction<char>('a', 'b', 'e') { ID = 20 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 30 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 40 });

            Apriori<char> method = new Apriori<char>();
            ItemSets<char> itemsets = method.MinePatterns(database, 0.5, new List<char>() { 'a', 'b', 'c', 'd', 'e' });
            for (int i = 0; i < itemsets.Count; ++i)
            {
                ItemSet<char> itemset = itemsets[i];
               
                Console.WriteLine(itemset);
            }
        }
    }
}

Apriori with DB Partitioning

The sample codes shows how to use Apriori with DB Partitioning to find the frequent item sets from a transaction database:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTAprioriWithDbPartitioning
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('a', 'c', 'd', 'e') { ID = 10 });
            database.Add(new Transaction<char>('a', 'b', 'e') { ID = 20 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 30 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 40 });

            AprioriWithDbPartitioning<char> method = new AprioriWithDbPartitioning<char>();

            
            ItemSets<char> itemsets = method.MinePatterns(database, 0.5, new List<char>() { 'a', 'b', 'c', 'd', 'e' }, 3);
            for (int i = 0; i < itemsets.Count; ++i)
            {
                ItemSet<char> itemset = itemsets[i];
               
                Console.WriteLine(itemset);
            }
        }
    }
}

FP-Growth

The sample codes shows how to use fp-growth to mine patterns and discover closed patterns:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTFPGrowth
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('f', 'a', 'c', 'd', 'g', 'i', 'm', 'p') { ID = 100 });
            database.Add(new Transaction<char>('a', 'b', 'c', 'f', 'l', 'm', 'o') { ID = 200 });
            database.Add(new Transaction<char>('b', 'f', 'h', 'j', 'o', 'w') { ID = 300 });
            database.Add(new Transaction<char>('b', 'c', 'k', 's', 'p') { ID = 400 });
            database.Add(new Transaction<char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n') { ID = 500 });


            Console.WriteLine("Using FPGrowth");
            DateTime start_time = DateTime.UtcNow;
            FPGrowth<char> method = new FPGrowth<char>();
            ItemSets<char> fis = method.MinePatterns(database, Transaction<char>.ExtractDomain(database), 0.4);
            DateTime end_time = DateTime.UtcNow;
            Show(fis);
            Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds);

            Console.WriteLine("Finding Closed Pattern");
            Show(method.FindMaxPatterns(database, Transaction<char>.ExtractDomain(database), 0.4));

            Console.WriteLine("Using baseline Apriori");
            start_time = DateTime.UtcNow;
            Apriori<char> baseline_method = new Apriori<char>();
            fis = method.MinePatterns(database, Transaction<char>.ExtractDomain(database), 0.4);
            end_time = DateTime.UtcNow;
            Show(fis);
            Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds);
        }

        private static void Show(ItemSets<char> fis)
        {
            for (int i = 0; i < fis.Count; ++i)
            {
                Console.WriteLine("{0} (Support: {1})", fis[i], fis[i].Support);
            }
        }
    }
}

cs-pattern-discovery

Pattern Discovery implemented in C#

Usage

Apriori

The sample codes shows how to use Apriori to find the frequent item sets from a transaction database:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTApriori
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('a', 'c', 'd', 'e') { ID = 10 });
            database.Add(new Transaction<char>('a', 'b', 'e') { ID = 20 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 30 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 40 });

            Apriori<char> method = new Apriori<char>();
            ItemSets<char> itemsets = method.MinePatterns(database, 0.5, new List<char>() { 'a', 'b', 'c', 'd', 'e' });
            for (int i = 0; i < itemsets.Count; ++i)
            {
                ItemSet<char> itemset = itemsets[i];
               
                Console.WriteLine(itemset);
            }
        }
    }
}

Apriori with DB Partitioning

The sample codes shows how to use Apriori with DB Partitioning to find the frequent item sets from a transaction database:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTAprioriWithDbPartitioning
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('a', 'c', 'd', 'e') { ID = 10 });
            database.Add(new Transaction<char>('a', 'b', 'e') { ID = 20 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 30 });
            database.Add(new Transaction<char>('b', 'c', 'e') { ID = 40 });

            AprioriWithDbPartitioning<char> method = new AprioriWithDbPartitioning<char>();

            
            ItemSets<char> itemsets = method.MinePatterns(database, 0.5, new List<char>() { 'a', 'b', 'c', 'd', 'e' }, 3);
            for (int i = 0; i < itemsets.Count; ++i)
            {
                ItemSet<char> itemset = itemsets[i];
               
                Console.WriteLine(itemset);
            }
        }
    }
}

FP-Growth

The sample codes shows how to use fp-growth to mine patterns and discover closed patterns:

using System;
using System.Collections.Generic;
using PatternDiscovery.FrequentPatterns;

namespace PatternDiscovery.FT
{
    public class FTFPGrowth
    {
        public static void Example()
        {
            List<Transaction<char>> database = new List<Transaction<char>>();
            database.Add(new Transaction<char>('f', 'a', 'c', 'd', 'g', 'i', 'm', 'p') { ID = 100 });
            database.Add(new Transaction<char>('a', 'b', 'c', 'f', 'l', 'm', 'o') { ID = 200 });
            database.Add(new Transaction<char>('b', 'f', 'h', 'j', 'o', 'w') { ID = 300 });
            database.Add(new Transaction<char>('b', 'c', 'k', 's', 'p') { ID = 400 });
            database.Add(new Transaction<char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n') { ID = 500 });


            Console.WriteLine("Using FPGrowth");
            DateTime start_time = DateTime.UtcNow;
            FPGrowth<char> method = new FPGrowth<char>();
            ItemSets<char> fis = method.MinePatterns(database, Transaction<char>.ExtractDomain(database), 0.4);
            DateTime end_time = DateTime.UtcNow;
            Show(fis);
            Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds);

            Console.WriteLine("Finding Closed Pattern");
            Show(method.FindMaxPatterns(database, Transaction<char>.ExtractDomain(database), 0.4));

            Console.WriteLine("Using baseline Apriori");
            start_time = DateTime.UtcNow;
            Apriori<char> baseline_method = new Apriori<char>();
            fis = method.MinePatterns(database, Transaction<char>.ExtractDomain(database), 0.4);
            end_time = DateTime.UtcNow;
            Show(fis);
            Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds);
        }

        private static void Show(ItemSets<char> fis)
        {
            for (int i = 0; i < fis.Count; ++i)
            {
                Console.WriteLine("{0} (Support: {1})", fis[i], fis[i].Support);
            }
        }
    }
}

Release Notes

Pattern Discovery Algorithms such as Apriori and FP-Growth in .NET 4.6.1

Dependencies

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 387 5/2/2018