Skip to content
/ CPT Public

Compact prediction trees for fast sequence prediction using Machine Learning

License

Notifications You must be signed in to change notification settings

ashubham/CPT

Repository files navigation

Compact Prediction Tree

npm version

Sequence Prediction

This is an implementation of CPT algorithm for Fast Sequence Prediction. Its written in Pure Javascript and can be run both in NodeJS and the browser.

The library is based on these research papers:

  1. Compact Prediction Tree: A Losless Model for Accurate Sequence Prediction

  2. CPT+: Decreasing the time/space complexity of the Compact Prediction Tree

Install

$ npm i compact-prediction-tree

Usage

import CPT from 'compact-prediction-tree';

let model = new CPT();
let data = [
    ['hello', 'how', 'are', 'you'],
    ['hello', 'how', 'are', 'your', 'studies', 'going', '?'],
    ['This', 'is', 'a', 'test'],
    ['How', 'does', 'this', 'work']
]
model.train(
    data // Training Data
);

let target = [
    ['how', 'are']
];
let predictions = model.predict(
    target, // Test input
    2, // The number of last elements that will be used
       // to find similar sequences, (default: target.length)
    2  // The number of predictions required.
);

console.log(predictions) // [['you'], ['your']]

It works on Strings/Number sequences. Perf optimizations are pending such as compression of frequent sequences. Pull requests are welcome!

About

Compact prediction trees for fast sequence prediction using Machine Learning

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published