Skip to main content

K-Nearest Neighbors Time Series Prediction with Invariances

Project description

PyPI - Downloads PyPI - Format PyPI - Implementation PyPI - License PyPI - Status PyPI - Version PEP8 Workflow codecov Release Last Commit Forks Repo Stars

logo.png

K-Nearest Neighbors Time Series Prediction with Invariances (KNN-TSPI) algorithm implementation in python. For details about the model access the paper.

Installation

Dependencies

The package depends on the following third party libraries:

  • numpy

User Installation

Make sure you have pip package manager installed in your environment, then run:

pip install knn-tspi

Getting Started

Once the package is installed successfully, you can import the KNeighborsTSPI class and start forecasting univariate time series in a scikit-learn like manner.

import numpy as np

from knn_tspi import KNeighborsTSPI


data = 0.5 * np.arange(60) + np.random.randn(60)

model = KNeighborsTSPI()
model.fit(data)

y = model.predict(h=5)

For more detailed examples on how to use the package access examples.

Development

Source Code

Clone the repo with the command:

git clone https://github.com/GDalforno/KNN-TSPI.git

Setup

Create a python virtual environment and activate it with the command:

python3.11 -m venv .venv
source .venv/bin/activate

Then, set the enviroment up with the command:

make setup-dev

Testing

Once the setup is completed, launch the test suite for sanity check with:

make test-dev

Contributing

You can contributing to the project by opening issues, pull requests and reviewing the code. It will help us a lot if you reference the package on blog posts, articlesm social media, etc.

License

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

Changelog

See the changelog for a history of notable changes to knn-tspi.

Project History

During my research in the field of application of machine learning to forecast time series in 2020, I stumbled with a lack of algorithms and frameworks specialized in this task.

One of my colleagues, Moisés Rocha, send me the paper of a modified KNN for time series prediction along with the experiment code written in MATLAB to help me out with my work. A coupled of days after it, I managed to port the code to both python and R and created this repo to store the resulted files.

Throughtout the years that followed, I have seen a growing interest in this repo, and now, I decided to publish it on pip to make it easier for people to include the model in their time series forecasting toolbox as I did a couple of years ago. As far as I know, there is no other implementation of the KNN-TSPI out there.

I am not planning on creating a CRAN package to distribute the model for the R community anytime soon. With that being said, feel free to implement it yourself if you wish. The core R code can be found here.

Communication

References

  1. Parmezan, Antonio & Batista, Gustavo. (2015). A Study of the Use of Complexity Measures in the Similarity Search Process Adopted by kNN Algorithm for Time Series Prediction. 45-51. 10.1109/ICMLA.2015.217.

Project details


Download files

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

Source Distribution

knn_tspi-1.0.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

knn_tspi-1.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file knn_tspi-1.0.1.tar.gz.

File metadata

  • Download URL: knn_tspi-1.0.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.9 Linux/6.5.0-1021-azure

File hashes

Hashes for knn_tspi-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e5417b48842c0ddd6f439011a2cf52bfc50caf2398eda31ebdc668804a14a506
MD5 b7f03138098dafffb937dc08efbb32d4
BLAKE2b-256 bbabdb9a16d03789a4758a525e9d15f9a20c12ca2968fe636192e82fc5ae82cf

See more details on using hashes here.

File details

Details for the file knn_tspi-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: knn_tspi-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.9 Linux/6.5.0-1021-azure

File hashes

Hashes for knn_tspi-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5204e042c2ab1d460e07530405add1f3836d66d6a0311c9b30846904a85a41fb
MD5 91300efea82f2cfd1af76a3583d436e2
BLAKE2b-256 abc7f1dadb07b2df4773609907fe90d2a49b6b240a4917444611a0f0404964df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page