Skip to main content

Test and Convert non-stationary time-series to stationary

Project description

📊 StationarityToolkit

StationarityToolkit is a Python library designed to help you analyze and transform time series data for stationarity. It offers a suite of statistical tests and automated transformations to detect and handle both trend and variance non-stationarity.

Whether you're building a forecasting model or preparing data for analysis, this toolkit makes your preprocessing easier and more reliable.

🚀 Features

✅ 1. Test for Variance Non-Stationarity

  • Use the Phillips-Perron test to detect variance instability.

✅ 2. Test for Trend Non-Stationarity

  • Use both ADF (Augmented Dickey-Fuller) and KPSS (Kwiatkowski-Phillips-Schmidt-Shin) tests to check for trend-based non-stationarity.

🔧 3. Remove Trend Non-Stationarity

  • Automatically apply:
    • Trend differencing
    • Seasonal differencing
    • Or a combination of both
  • Optimized for weekly seasonal data.

🔧 4. Remove Variance Non-Stationarity

  • Automatically apply transformations like:
    • Logarithmic
    • Square root
    • Box-Cox
  • Selects the best transformation based on statistical significance.
  • Skips transformation if variance is already stationary.

🧹 5. Remove All Non-Stationarity

  • Combine both variance and trend removal in one pipeline:
    • Detect and remove variance issues first
    • Then proceed to handle trend non-stationarity

🛠️ Installation

pip install StationarityToolkit

🧪 Quick Start:

  1. Import the toolkit:
     from stationarity_toolkit.stationarity_toolkit import StationarityToolkit
    
  2. Initialize the Toolkit:
     toolkit = StationarityToolkit(alpha=0.05)
    

⚙️ Usage Guide

  1. ✅ Test for Stationarity:
     toolkit.perform_pp_test(ts)     # Phillips-Perron test for variance non-stationarity
     toolkit.adf_test(ts)            # Augmented Dickey-Fuller test for trend
     toolkit.kpss_test(ts)           # KPSS test for trend
    
  2. 🔧 Remove Variance Non-Stationarity
     toolkit.remove_var_nonstationarity(ts_as_a_dataframe)
    
  • Checks if variance non-stationarity exists.
  • Applies log, square root, and Box-Cox transformations.
  • Selects the transformation that produces the lowest p-value.
  • Skips transformation if unnecessary.
  1. 🔧 Remove Trend Non-Stationarity
     toolkit.remove_var_nonstationarity(ts_as_a_dataframe)
    
  • Applies differencing techniques:
    • Lag differencing
    • Seasonal differencing
    • Combination of both
  • Evaluates each using ADF and KPSS tests to find the best transformation.
  • ⚠️ Currently supports weekly seasonality only.
  1. 🧹 Remove All Non-Stationarity
    toolkit.remove_nonstationarity(ts_as_a_dataframe)
    
  • Runs both variance and trend checks/removal:
    • Removes variance non-stationarity (if present)
    • Then removes trend non-stationarity

💡 Why Stationarity Matters

  • Most classical and deep learning time series models (ARIMA, VAR, Prophet, LSTM) assume that the data is stationary. Non-stationary data can lead to:
    • Spurious regressions
    • Poor model accuracy
    • Invalid statistical inferences

StationarityToolkit helps you automate this critical preprocessing step with minimal manual intervention.

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

stationaritytoolkit-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

stationaritytoolkit-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file stationaritytoolkit-0.1.2.tar.gz.

File metadata

  • Download URL: stationaritytoolkit-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.18

File hashes

Hashes for stationaritytoolkit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e6c92fbb5c887a0ad596471b0873519d88d42876075834fef8f37b8837a21142
MD5 7ccdd81b03ff4be3c7c8d4c336067efc
BLAKE2b-256 47ef2c78f1c3be58b1803e2bc03adf535ac1a7609cda14125a78bd3b2de5019e

See more details on using hashes here.

File details

Details for the file stationaritytoolkit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for stationaritytoolkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3fccb63e2b378fc3432e85a2e0498f2f6f9596cfce9b733bc85d8681688e7c69
MD5 ddbc525e0ec0f6a0d184a0c0939015b7
BLAKE2b-256 8aa86b3c8cf1ac61a0551bed5e7e9c613305c79a602b67864b0792e45c679eed

See more details on using hashes here.

Supported by

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