Skip to main content

CPT

PyPI version Downloads License

What is it ?

This project is a cython open-source implementation of the Compact Prediction Tree algorithm using multithreading.

CPT is a sequence prediction model. It is a highly explainable model specialized in predicting the next element of a sequence over a finite alphabet.

This implementation is based on the following research papers:

Installation

You can simply use pip install cpt.

Simple example

You can test the model with the following code:

from cpt.cpt import Cpt
model = Cpt()

model.fit([['hello', 'world'],
           ['hello', 'this', 'is', 'me'],
           ['hello', 'me']
          ])

model.predict([['hello'], ['hello', 'this']])
# Output: ['me', 'is']

For an example with the compatibility with sklearn, you should check the documentation.

Features

Train

The model can be trained with the fit method.

If needed the model can be retrained with the same method. It adds new sequences to the model and do not remove the old ones.

Multithreading

The predictions are launched by default with multithreading with OpenMP.

The predictions can also be launched in a single thread with the option multithread=False in the predict method.

You can control the number of threads by setting the following environment variable OMP_NUM_THREADS.

Pickling

You can pickle the model to save it, and load it later via pickle library.

from cpt.cpt import Cpt
import pickle


model = Cpt()
model.fit([['hello', 'world']])

dumped = pickle.dumps(model)

unpickled_model = pickle.loads(dumped)

print(model == unpickled_model)

Explainability

The CPT class has several methods to explain the predictions.

You can see which elements are considered as noise (with a low presence in sequences) with model.compute_noisy_items(noise_ratio).

You can retrieve trained sequences with model.retrieve_sequence(id).

You can find similar sequences with find_similar_sequences(sequence).

You can not yet retrieve automatically all similar sequences with the noise reduction technique.

Tuning

CPT has 3 meta parameters that need to be tuned. You can check how to tune them in the documentation. To tune you can use the model_selection module from sklearn, you can find an example here on how to.

Benchmark

The benchmark has been made on the FIFA dataset, the data can be found on the SPMF website.

Using multithreading, CPT was able to perform around 5000 predictions per second.

Without multithreading, CPT predicted around 1650 sequences per second.

Details on the benchmark can be found here.

Further reading

A study has been made on how to reduce dataset size, and so training / testing time using PageRank on the dataset.

The study has been published in IJIKM review here. An overall performance improvement of 10-40% has been observed with this technique on the prediction time without any accuracy loss.

One of the co-author of CPT has also published an algorithm subseq for sequence prediction. An implementation can be found here

Support

If you enjoy the project and wish to support me, a buymeacoffee link is available.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpt-1.3.5-cp313-cp313-win_amd64.whl (104.1 kB view details)

Uploaded CPython 3.13Windows x86-64

cpt-1.3.5-cp313-cp313-win32.whl (90.0 kB view details)

Uploaded CPython 3.13Windows x86

cpt-1.3.5-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpt-1.3.5-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpt-1.3.5-cp313-cp313-macosx_13_0_x86_64.whl (480.4 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

cpt-1.3.5-cp312-cp312-win_amd64.whl (104.8 kB view details)

Uploaded CPython 3.12Windows x86-64

cpt-1.3.5-cp312-cp312-win32.whl (90.5 kB view details)

Uploaded CPython 3.12Windows x86

cpt-1.3.5-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpt-1.3.5-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpt-1.3.5-cp312-cp312-macosx_13_0_x86_64.whl (481.1 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

cpt-1.3.5-cp311-cp311-win_amd64.whl (104.0 kB view details)

Uploaded CPython 3.11Windows x86-64

cpt-1.3.5-cp311-cp311-win32.whl (89.9 kB view details)

Uploaded CPython 3.11Windows x86

cpt-1.3.5-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpt-1.3.5-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpt-1.3.5-cp311-cp311-macosx_13_0_x86_64.whl (469.3 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

cpt-1.3.5-cp310-cp310-win_amd64.whl (101.9 kB view details)

Uploaded CPython 3.10Windows x86-64

cpt-1.3.5-cp310-cp310-win32.whl (90.2 kB view details)

Uploaded CPython 3.10Windows x86

cpt-1.3.5-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpt-1.3.5-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpt-1.3.5-cp310-cp310-macosx_13_0_x86_64.whl (470.5 kB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

File details

Details for the file cpt-1.3.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cpt-1.3.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 104.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for cpt-1.3.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6367510e53bae8f81de5b18c5543f6f0ef64d57cbaced697dd556c65cdb2b1a1
MD5 1420859d82b7b3108a6fa882f752febf
BLAKE2b-256 82e547c4ad7df78071104a318687bcec7ee3d0fd6a4dfd4d07379069f2dec2fa

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp313-cp313-win32.whl.

File metadata

  • Download URL: cpt-1.3.5-cp313-cp313-win32.whl
  • Upload date:
  • Size: 90.0 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for cpt-1.3.5-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 99361e90da323babbac9667f0003265b12f74fce9c83ea1b056037d33c3e0df1
MD5 f7004857370cfdddd0a17566bb7b0ea8
BLAKE2b-256 24fc019f5321aaa80224423758debb4450377a03eb9453585a59eb28f60dbec0

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 576ae075210299d86f85e71b30e2939dbb4e2ffa7a31986ff0ba8e3653ce3c71
MD5 474f014b679572c07fb7639952ef4502
BLAKE2b-256 943b8d0dcbb7a5c24034cd759969d3017b2967be1d08fbc832cd0d2d58a738fa

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7642655c8bbf96c8bce31a4af970332bfa70f762347ad8ad3e77384f28733ba5
MD5 7fca09428ad0b5dc87968dcaff004115
BLAKE2b-256 4b6454b004d9f6b3be31337fb216f56cee52fd66f0f68b1bac9097ebf1575ecb

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 71919faee0bc41eeeab5b24a7541c93c8453b5cfeeceee9728ef3981cf9a97b1
MD5 4c3384c4d7b8a44b3b64017b22a1feec
BLAKE2b-256 003a3cef00ae0e6c1f8d60d3c5b85196609a34170390c501eefacf796dd67add

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cpt-1.3.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 104.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cpt-1.3.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f78a6e6cf39a5646b9e87c342ba27de313d08ce2264741da62d483f41821db4
MD5 d444762df4c7d7aa30c26122cc3e6416
BLAKE2b-256 702cddfa535e2d4f50fcaa555c6a3c637d4d74c001c256497a9d9c2db3d9fb71

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp312-cp312-win32.whl.

File metadata

  • Download URL: cpt-1.3.5-cp312-cp312-win32.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cpt-1.3.5-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 858678625f8acd27a6b38e3bb276dc26579df3f8d40540fdbc736df7a825c3a1
MD5 b3446de03a9b3495b5b8701cd477199d
BLAKE2b-256 1407f578d99abc42d17da582b44a43e0646c29ff0773a47d83c99b9528f6c8d8

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 38fef24343253855d9ea8c58f16cf3d84d133882bd559b4869a963de78d1d596
MD5 4a82f548cbf71e25f3f546f171315e9f
BLAKE2b-256 c9757189139dd072ea237078e6a3df297c98fc61989649c6dceaf6440c7078f3

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3e20d5275c697b137d02cb7870c7c2f1641305e3e31468053f314588794ea6c6
MD5 255b80d09e4303ddd702d9b24e5c4f4b
BLAKE2b-256 416580d2e5a198f363c4b781499853b4659f9b1cfd4831982f1edf399b8f8468

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 41afe85d68b53a9d8cb5af30033792065ed7657c0e66032632dab796e89b0ae6
MD5 3c1ad5c7f611341a2d3d1594211c9c73
BLAKE2b-256 40ff18dec2c93ef59034f472bcc56cf505a37bb19735128f4fda6e5e32eaa717

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cpt-1.3.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 104.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for cpt-1.3.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f5d23ed5dc29fef39de57413ae3d213fa447fd0b9997aa6c697ac4d56ec3b5fb
MD5 248865eb6af004da434c2239d9213f84
BLAKE2b-256 b872cfb3fafce89e9469fa6b233a216bf2092e82e01be97ad61359b5a668f487

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp311-cp311-win32.whl.

File metadata

  • Download URL: cpt-1.3.5-cp311-cp311-win32.whl
  • Upload date:
  • Size: 89.9 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for cpt-1.3.5-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 de2d36acc09cbf4ab73a66c299f3b58a2d8eb50ec998447652ab2ca034cab254
MD5 24caabb30017779fc8b5d70533d34d0e
BLAKE2b-256 c9af1c49514a6d4603f87d79c2336f1d7232efa96c9d97bc9a9339b571faa2f3

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f93929208bf05416a3c024081f9fe3602e6628fe14e232c09585d16397a1402
MD5 138d5b15302836503efc2c552468329b
BLAKE2b-256 4aa3875671bde425d6d5c01694fad3a724e322b381559547865a4dc161f6390b

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 59e0ade99b308e7d9c8261b74d4ea0871ff36bd71661fe25ca60c4f86fa28b2d
MD5 2b50db156ee42a7f34a022e6f7975a05
BLAKE2b-256 0a56a034af57a2d46b3024263c5d9a42bd67b1f7502b3cdc7f378e6826f0a9b0

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 3d1c1a2f49edf4b8be278854a7ece0f675e17f64aeb4cf33b59a74be03093a14
MD5 333e6e7b0feb5ad41a36288b051f9514
BLAKE2b-256 f3debd81126e3ca4b678bf5b98ee3ada71ea1ca38749cb1161199ee2a207ab28

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cpt-1.3.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 101.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for cpt-1.3.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a77c881f0b8c999ce74775580f5164e7dd38fc1e78bf099cad22e7eb5e43b165
MD5 4c3be8de796f99cc8ea0a7006c61baed
BLAKE2b-256 9fc745509d8af51ec414c2accdc721c7fb77c30cc63ad175dc61b519ac0bd3cf

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp310-cp310-win32.whl.

File metadata

  • Download URL: cpt-1.3.5-cp310-cp310-win32.whl
  • Upload date:
  • Size: 90.2 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for cpt-1.3.5-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 959c47f488daa5ade40086748f6a81cb9f1c727ed37ae079a2c5d370a9208697
MD5 a64d0b46e3a02010b503daaa710c3dc6
BLAKE2b-256 1ce81543c1bc3b5766f70b2c9cdde62ea9f1115f4f71afd9182dcfaec71b8485

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a08bd6bf3e6dfa5c813840230628c35c5dba9f5db9908499af0689eb545d9974
MD5 7d57805abed2d40e8e5c6b01c8062bf7
BLAKE2b-256 aa2b90c0b5902219b8ec659950580529ed62c242e7d3392bcc3bfc6291e1acf7

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 65540a7bcf9367e0ce321bc3aa6df178001b5926bcab48d8815d64d0c2783544
MD5 e23752e482349e86e00f4fa2e7ac13db
BLAKE2b-256 354e2b4158bda1887d60e0e8377d1f7d96666c3ae9890a4ccac40227ae11b636

See more details on using hashes here.

File details

Details for the file cpt-1.3.5-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpt-1.3.5-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 6ff5726fa89f94c1ee5cfbc3d0983a4d75e2209ab76069849cec916a6178ef15
MD5 a6e7921473068ebcf1a12211c5f77a5e
BLAKE2b-256 f0e520993d4972d516834d86e474f4fdcd6eaac7d5001fab8252ee99a39f8f4a

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.6

42 files

This release

1.3.5 This release

20 files

1.3.4

31 files

1.3.3

25 files

1.3.2

29 files

1.3.1

21 files

1.3.0

26 files

1.2.3

21 files

1.2.2

19 files

1.2.1

19 files

1.2.0

10 files

1.0.2

7 files

1.0.1

7 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page