Metadata-Version: 2.1
Name: pypsf
Version: 1.0.1
Summary: Python implementation of the Pattern Sequence Forecasting (PSF) algorithm
Project-URL: Homepage, https://github.com/mamei16/PyPSF
Project-URL: Bug Tracker, https://github.com/mamei16/PyPSF/issues
Author: Marcel Meimbresse
License: MIT License Copyright (c) 2020 Marcel Meimbresse
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is furnished
        to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice (including the next
        paragraph) shall be included in all copies or substantial portions of the
        Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
        FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
        OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
        WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
        OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: numpy>=1.21
Requires-Dist: scikit-learn>=1.0
Description-Content-Type: text/markdown

# PyPSF
This project provides a valid python implementation of the Pattern Sequence 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](https://github.com/mamei16/PyPSF/blob/9b6d395cf2b8288937e7b4bca7ee5752e2e1c435/psf_description.pdf).

## 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
 
    
