Skip to content

alexisfacques/node-apriori

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node-Apriori

Apriori Algorithm implementation in TypeScript / JavaScript.

Getting Started

Performances

This implementation does not generate k-candidates as efficiently as it possibly could, as it adopts a brute-force approach: Every k-itemset is considered as a potential candidate, and an additional step is required to prune the unnecessary ones. More information about this question here.

The Apriori Algorithm is a great, easy-to-understand algorithm for frequent-itemset mining. However, faster and more memory efficient algorithms such as the FPGrowth Algorithm have been proposed since it was released.

If you need a more efficient frequent-itemset mining algorithm, consider checking out my implementation of the FPGrowth Algorithm.

Installing

This is a Node.js module available through the npm registry.

Installation is done using the npm install command:

$ npm install --save node-apriori

Example of use

In your TypeScript project, import and use Apriori as follows. Same example with a JavaScript syntax is available here.

import { Apriori, Itemset, IAprioriResults } from 'node-apriori';

let transactions: number[][] = [
    [1,3,4],
    [2,3,5],
    [1,2,3,5],
    [2,5],
    [1,2,3,5]
];

// Execute Apriori with a minimum support of 40%. Algorithm is generic.
let apriori: Apriori<number> = new Apriori<number>(.4);

// Returns itemsets 'as soon as possible' through events.
apriori.on('data', (itemset: Itemset<number>) => {
    // Do something with the frequent itemset.
    let support: number = itemset.support;
    let items: number[] = itemset.items;
});

// Execute Apriori on a given set of transactions.
apriori.exec(transactions)
    .then( (result: IAprioriResults<number>) => {
        // Returns both the collection of frequent itemsets and execution time in millisecond.
        let frequentItemsets: Itemset<number>[] = result.itemsets;
        let executionTime: number = result.executionTime;
    });

Building from source

  • Clone this repository:
    git clone https://github.com/alexisfacques/Node-Apriori.git
    cd Node-Apriori
  • Install the project's dependencies with npm:
    npm install
  • Compile the project's sources to NodeJS executable JavaScript:
    npm run tsc
  • This should allow you to execute the given example as follows:
    npm test

License

This project is licensed under the MIT License - see the LICENSE file for details