STF: seasonal-trend decomposition using the Fast Fourier transform
Project description
stf_decomposition
stf_decomposition: Seasonal-Trend decomposition using the Fast Fourier transform
Installation
Installing stf_deocmposition can be done with pip installation syntax
pip install stf-decomposition
The package is tested on Python 3.7, 3.8 and 3.9.
Getting Started
In order to use stf_decomposition you will need a time series dataset of type pandas DataFrame or pandas Series. You will also need to specify the following input variables:
- window: A string indicating the name of a window function for use during the Fast Fourier transform process to reduce spectral leakage. The possible window inputs can be found in the get_window scipy documentation.
- period: An integer indicating the period of the time series input data. The period must be specified by the user if the input data does not have a frequency.
Optional input variable:
- seasonal: An integer indicating the seasonal window of the time series input data.
If no input is given than an optimization function will be run to find the seasonal window that produces the smallest correlation between the seasonal and trend decomposed components.
The code below shows reading in a Carbon Emissions time series dataset as a pandas DataFrame and
creating an
STF
object from the DataFrame with a "blackman" window. The CO2 input data has a frequency so a user specified period is not needed.
co2 = pd.read_csv('data/co2.csv', index_col='date', parse_dates=True, squeeze=True)
stf = STF(co2, "blackman")
Example
This demonstration will walkthrough the complete process of reading in data,
creating an STF
object, fitting the object,
and plotting the decomposed components.
- Read in time series data as a pandas DataFrame or Series
from stf_decomposition import STF
data = pd.read_csv('data/AirPassengers.csv', index_col = "Month", parse_dates=True, squeeze=True)
- Create an
STF
object and indicate a window, period (if needed), and seasonal window (if desired).
stf = STF(data, window = "hanning")
- Fit the object. After fitting the decomposition you can access the trend, seasonal, and residual components.
res = stf.fit()
# View decomposed components
print(res.trend.head())
print(res.seasonal.head())
print(res.residual.head())
- Plot the trend, seasonal, and residual components
fig = res.plot()
Testing
The package include a test suite that can be run in the main directory using the pystest library
pytest
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
File details
Details for the file stf-decomposition-0.1.2.tar.gz
.
File metadata
- Download URL: stf-decomposition-0.1.2.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41dc6f45ffbcd3009c3dfa09b19634274999aa6feeff35de58319ed7a44ac482 |
|
MD5 | e42f283499308ce284e196ca1a4a1624 |
|
BLAKE2b-256 | 8003c5fa4817730361676427ff32bcd73b3ebd2e83eb7fd3cbc742113ef4e99f |
File details
Details for the file stf_decomposition-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: stf_decomposition-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8edfe53c7e0eb481fc1ec7284e0c367315c5e7e2855de863c153dbf3b7fc3cc4 |
|
MD5 | c3ae5b0bf4347d475e065eb30ea6ccdc |
|
BLAKE2b-256 | 39c8b0d4ecffb15ee42f4aa48bf09c99059d31d932b18b674fb2581aed1d529b |