Python implementation of the Pattern Sequence Based Forecasting (PSF) algorithm
Project description
PyPSF
This project provides a python implementation of the Pattern Sequence Based Forecasting (PSF) algorithm. For a detailed description of the PSF algorithm and some of the practical issues I encountered when using it, see this PDF file.
Installation
pip install pypsf
Dependencies
- scikit-learn
- numpy
Example Usage
import numpy as np
from pypsf import Psf
t_series = np.array([1, 2, 3, 1, 2, 3, 1, 2, 3])
train = t_series[:6]
test = t_series[6:]
psf = Psf(cycle_length=3)
psf.fit(train)
pred = psf.predict(len(test))
print(test) # [1 2 3]
print(pred) # [1. 2. 3.]
Parameters
class Psf
- cycle_length: int
The cycle length c - k: int (optional), default None
The user-defined number of desired clusters when running K-means on the cycles - w: int (optional), default None
The user-defined window size - suppress_warnings: bool (optional), default False
Suppress all warnings - apply_diff: bool (optional), default False
Apply first order differencing to the time series before applying PSF - diff_periods: int (optional), default 1
Periods to shift for calculating difference, to allow for either ordinary or seasonal differencing. Ignore if apply_diff=False - detrend: bool (optional), default False
Remove a linear trend from the series prior to applying PSF by fitting a simple linear regression model. The trend is subsequently re-added to the predictions.
Psf.fit
- data:
The input time series - k_values: iterable[int] (optional), default tuple(range(3, 12))
The set of candidate values of k to test when finding the "best" k number of clusters based on the training data - w_values: iterable[int] (optional), default tuple(range(1, 20))
The set of candidate values of w to test when finding the "best" window size w based on the training data
Psf.predict
- n_ahead: int
The number of values to predict
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypsf-1.0.2.tar.gz.
File metadata
- Download URL: pypsf-1.0.2.tar.gz
- Upload date:
- Size: 518.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
351a87e698e4e46acffded7aa968cc16a827a09fab5e521d5cf1438635a580b3
|
|
| MD5 |
74cd825b6776c7cdfa994c53cd5eda26
|
|
| BLAKE2b-256 |
2f2ab8d176bf29b5792ac72e7e8baed5dac0773cb83f6326cf1bf4b52854c9fb
|
File details
Details for the file pypsf-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pypsf-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
709c62d894fb8951d8d766d27c4e5974eecc0f4e003c45d1c2c9772c9668c280
|
|
| MD5 |
cbcab07d17f469445c934ec30781f573
|
|
| BLAKE2b-256 |
18782d6955d3600ed0647f07c163c6d2849075ff9d1c13c82aa7e21cf5f4e26a
|