Metadata-Version: 2.5
Name: pytspredit
Version: 1.0.727
Summary: Time series prediction with tunable preprocessing (Python port of the R tspredit framework)
Project-URL: Homepage, https://github.com/cefet-rj-dal/pytspredit
Project-URL: Repository, https://github.com/cefet-rj-dal/pytspredit
Project-URL: Bug Tracker, https://github.com/cefet-rj-dal/pytspredit/issues
Author: Eduardo Ogasawara, Diego Carvalho, Eduardo Bezerra, Esther Pacitti, Fabio Porto, Fernando Alexandrino, Gustavo Guedes, Rebecca Salles, CEFET/RJ
Maintainer-email: Eduardo Ogasawara <eogasawara@ieee.org>
License: MIT
License-File: LICENSE
Keywords: experiment line,forecasting,machine learning,scikit-learn,time series
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Requires-Dist: matplotlib>=3.6
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: pydaltoolbox>=0.1.0
Requires-Dist: scikit-learn>=1.2
Requires-Dist: scipy>=1.10
Requires-Dist: statsmodels>=0.14
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: docs
Requires-Dist: ipykernel>=6; extra == 'docs'
Requires-Dist: jupytext>=1.16; extra == 'docs'
Requires-Dist: nbclient>=0.9; extra == 'docs'
Requires-Dist: nbconvert>=7; extra == 'docs'
Description-Content-Type: text/markdown

# pytspredit

[![PyPI version](https://img.shields.io/pypi/v/pytspredit.svg)](https://pypi.org/project/pytspredit/)
[![Python versions](https://img.shields.io/pypi/pyversions/pytspredit.svg)](https://pypi.org/project/pytspredit/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/cefet-rj-dal/pytspredit/blob/main/LICENSE)

Python port of the R [tspredit](https://github.com/cefet-rj-dal/tspredit) — **time series
prediction with tunable preprocessing**, built on the DAL Toolbox *Experiment Line*.

`pytspredit` provides a uniform, extensible interface for time series forecasting:
sliding-window modeling, normalization, filtering, lag mapping, data augmentation,
machine-learning and statistical regressors, and integrated hyperparameter tuning — reusing
classic Python libraries (scikit-learn, numpy, pandas, scipy, statsmodels) through thin
adapters and self-contained native implementations.

It is part of the DAL Python family:

- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** (foundation).
- Powers the forecasting-based detectors in **[pyharbinger](https://github.com/cefet-rj-dal/pyharbinger)** (time series event detection).

## Installation

```bash
pip install pytspredit
```

## Quickstart

```python
import pytspredit as ts

series = ts.datasets.tsd()["y"]                  # example series
windows = ts.ts_data(series, sw=10)              # sliding windows: columns t9 ... t0
samp = ts.ts_sample(windows, test_size=5)        # temporal train/test split
io_train = ts.ts_projection(samp.train)          # -> (input X, output t0)
io_test = ts.ts_projection(samp.test)

# a kNN regressor with min-max normalization and PACF-based lag selection
model = ts.TsKnn(ts.TsNormGminmax(), input_size=4, input_map=ts.TsLagmap("pacf"), k=3)
model.fit(io_train.input, io_train.output)

forecast = model.predict(io_test.input.iloc[[0]], steps_ahead=5)   # 5 steps ahead
print(model.evaluate(io_test.output.to_numpy(), forecast)["metrics"])
```

## What's included

Every forecasting component follows a uniform Experiment Line interface (`fit` → `predict` /
`transform` → `evaluate`), so preprocessing, lag selection, augmentation, and regressors can
be composed and tuned together.

| Group | Classes & Functions |
|---|---|
| **Core data utilities** | `ts_data`, `ts_projection`, `ts_sample`, `adjust_ts_data`, `ts_head` |
| **Regression base & metrics** | `TsReg`, `TsRegSW`, `mse_ts`, `smape_ts`, `r2_ts` |
| **Normalizations** | `TsNormNone`, `TsNormGminmax`, `TsNormSwminmax`, `TsNormDiff`, `TsNormAn` (adaptive; 4 operators) |
| **Lag mapping** | `TsLagmap` (12 strategies: recent, even, geom, acf, pacf, peaks, seasonal, acf/pacf-seasonal, blocks, mutual information, mRMR) |
| **Filters** | `TsFilNone`, `TsFilMa`, `TsFilEma`, `TsFilWinsor`, `TsFilRecursive`, `TsFilFft`, `TsFilSmooth`, `TsFilHp`, `TsFilGabor`, `TsFilLowess`, `TsFilSes`, `TsFilQes`, `TsFilSeasAdj`, `TsFilSpline`, `TsFilKalman`, `TsFilEmd`, `TsFilRemd`, `TsFilWavelet` |
| **Augmentation** | `TsAugNone`, `TsAugFlip`, `TsAugStretch`, `TsAugShrink`, `TsAugJitter`, `TsAugWormhole`, `TsAugAwareness`, `TsAugAwaresmooth` |
| **Regressors** | `TsKnn`, `TsElm`, `TsRf`, `TsSvm`, `TsMlp`, `TsArima` (including `auto="cv"`), `TsDarima`, `TsWarma`, `TsDeterministic`, `TsPeriodic`, `TsPersist` |
| **Multivariate** | `ts_data_mv`, `adjust_ts_data_mv`, `ts_mv_spec`, `TsRegswMv`, `TsLmMv`, `TsVar`, `TsArimax` |
| **Tuning & benchmarking** | `TsTune`, `TsIntegtune`, `TsPredBench` |
| **Plotting** | `plot_series`, `plot_ts`, `plot_ts_pred`, `plot_ts_pred_mv` (matplotlib) |
| **Datasets** | `datasets.tsd()` and 20 `tspredbench` benchmark datasets as compact miniatures with on-demand full expansion via `datasets.loadfulldata(name)` |

## Guided Tutorial Track

If you are new to `pytspredit`, start with the guided tutorials in the
[GitHub examples collection](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples):

- [Tutorials](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/tutorial) — a
  10-part sequential learning path starting with classical ARIMA forecasting protocols
  (one-step, rolling-origin, multi-step), building a sliding-window MLP pipeline step by step
  (normalization, filtering, augmentation), and finishing with model comparison and integrated
  hyperparameter tuning.

## Thematic Example Collections

If you already know the basic forecasting workflow, jump directly to any thematic example
collection on GitHub:

- [Time-series data utilities](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/tsdata) — building sliding windows (`ts_data`), projecting inputs/targets (`ts_projection`), and temporal train/test splits (`ts_sample`).
- [Dataset examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/datasets) — `tsd` and the 20 benchmark datasets (`eunite`, `nn3`, `nn5`, `cats`, `santafe`, `ipeadata`, `m1`, `m3`, `m4`, `stocks`, and domain collections).
- [Filtering examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/filter) — smoothing, robust, spectral, decomposition (EMD/REMD, MODWT wavelet), state-space (Kalman), and seasonal-adjustment filters.
- [Lag mapping examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/lagmapping) — recency, spacing, autocorrelation, partial autocorrelation, seasonal, mutual information, and mRMR lag selection strategies.
- [Normalization examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/normalization) — global and sliding-window min-max, differencing, and adaptive normalization operators.
- [Data augmentation examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/augment) — jitter, flip, stretch, shrink, wormhole, awareness, and aware-smoothing augmenters.
- [Prediction examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/prediction) — ARIMA (including `auto="cv"`), kNN, SVM, Random Forest, MLP, ELM, DARIMA, WARMA, and deterministic baselines.
- [Multivariate examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/multivariate) — target-centered multivariate sliding windows (`TsRegswMv`), linear models (`TsLmMv`), `TsVar`, and `TsArimax`.
- [Tuning examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/tuning) — model hyperparameter tuning (`TsTune`) and integrated pipeline tuning (`TsIntegtune`).
- [Benchmark examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/benchmark) — multi-dataset, multi-model evaluation grids with `TsPredBench`.
- [Custom examples](https://github.com/cefet-rj-dal/pytspredit/tree/main/examples/custom) — extending `pytspredit` with custom predictors, filters, augmenters, and normalizers.

## Main Capabilities

- **Unified abstractions** for sliding-window data preparation, normalizers, filters, lag maps, augmenters, regressors, tuners, and benchmark harnesses.
- **Univariate and multivariate forecasting** across statistical (`TsArima`, `TsVar`, `TsArimax`), window-linear (`TsDarima`, `TsWarma`), deterministic, and machine-learning (`TsKnn`, `TsElm`, `TsRf`, `TsSvm`, `TsMlp`) models.
- **Tunable preprocessing pipelines** combining invertible normalizations, 18 time-series filters (including native EMD/REMD and MODWT wavelet engines), 12 lag-mapping strategies, and 8 data augmentation methods.
- **Integrated hyperparameter tuning** jointly optimizing input window size, preprocessing components, and model hyperparameters (`TsTune`, `TsIntegtune`).
- **Benchmarks and visualization** with 20+ built-in benchmark datasets (`datasets.loadfulldata`), reproducible comparison grids (`TsPredBench`), and forecast plotting utilities (`plot_ts_pred`, `plot_ts_pred_mv`).

## Related DAL projects

- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
- [pyharbinger](https://github.com/cefet-rj-dal/pyharbinger) — time series event detection (Python)
- [daltoolbox](https://github.com/cefet-rj-dal/daltoolbox) / [tspredit](https://github.com/cefet-rj-dal/tspredit) / [harbinger](https://github.com/cefet-rj-dal/harbinger) — R originals
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)

## License

MIT
