Code Monkey home page Code Monkey logo

node-apriori's Introduction

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

node-apriori's People

Contributors

alexisfacques avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-apriori's Issues

It doesn't compile

node_modules/node-apriori/dist/apriori.d.ts(16,22): error TS2420:
Class 'Apriori' incorrectly implements interface 'IAprioriEvents'.
Property 'on' is missing in type 'Apriori'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.