项目作者: chen0040

项目描述 :
Package provides java implementation of frequent pattern mining algorithms such as apriori, fp-growth
高级语言: Java
项目地址: git://github.com/chen0040/java-frequent-pattern-mining.git
创建时间: 2017-05-09T13:08:10Z
项目社区:https://github.com/chen0040/java-frequent-pattern-mining

开源协议:MIT License

下载


java-frequent-pattern-mining

Package provides java implementation of frequent pattern mining algorithms such as apriori, fp-growth

Build Status Coverage Status

Features

  • Apriori
  • FP-Growth

Install

Add the following dependency to your POM file:

  1. <dependency>
  2. <groupId>com.github.chen0040</groupId>
  3. <artifactId>java-frequent-pattern-mining</artifactId>
  4. <version>1.0.1</version>
  5. </dependency>

Usage

FP Growth

The sample code below shows how to use FPGrowth to obtain the frequent item sets from a list of transactions

  1. List<List<String>> database = new ArrayList<>();
  2. // each line below add a new transaction to the database
  3. database.add(Arrays.asList("f", "a", "c", "d", "g", "i", "m", "p"));
  4. database.add(Arrays.asList("a", "b", "c", "f", "l", "m", "o"));
  5. database.add(Arrays.asList("b", "f", "h", "j", "o", "w"));
  6. database.add(Arrays.asList("b", "c", "k", "s", "p"));
  7. database.add(Arrays.asList("a", "f", "c", "e", "l", "p", "m", "n"));
  8. AssocRuleMiner method = new FPGrowth();
  9. method.setMinSupportLevel(2);
  10. MetaData metaData = new MetaData(database);
  11. // obtain all frequent item sets with support level not below 2
  12. ItemSets frequent_item_sets = method.minePatterns(database, metaData.getUniqueItems());
  13. fis.stream().forEach(itemSet -> System.out.println("item-set: " + itemSet));
  14. // obtain the max frequent item sets
  15. ItemSets max_frequent_item_sets = method.findMaxPatterns(database, metaData.getUniqueItems());

Apriori

The sample code below shows how to use Apriori to obtain the frequent item sets from a list of transactions

  1. List<List<String>> database = new ArrayList<>();
  2. // each line below add a new transaction to the database
  3. database.add(Arrays.asList("f", "a", "c", "d", "g", "i", "m", "p"));
  4. database.add(Arrays.asList("a", "b", "c", "f", "l", "m", "o"));
  5. database.add(Arrays.asList("b", "f", "h", "j", "o", "w"));
  6. database.add(Arrays.asList("b", "c", "k", "s", "p"));
  7. database.add(Arrays.asList("a", "f", "c", "e", "l", "p", "m", "n"));
  8. AssocRuleMiner method = new Apriori();
  9. method.setMinSupportLevel(2);
  10. MetaData metaData = new MetaData(database);
  11. // obtain all frequent item sets with support level not below 2
  12. ItemSets frequent_item_sets = method.minePatterns(database, metaData.getUniqueItems());
  13. fis.stream().forEach(itemSet -> System.out.println("item-set: " + itemSet));
  14. // obtain the max frequent item sets
  15. ItemSets max_frequent_item_sets = method.findMaxPatterns(database, metaData.getUniqueItems());