Skip to main content

pytspredit

PyPI version Python versions License: MIT

Python port of the R 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 and augmentation, machine-learning and statistical regressors, and hyperparameter tuning — reusing the best of the Python ecosystem (scikit-learn, numpy, pandas, statsmodels) through thin adapters. Its value is not reimplementing algorithms, but the rigid, extensible interface that wraps them.

It is part of the DAL Python family:

  • Builds on pydaltoolbox — the foundation (Python port of the R daltoolbox), on PyPI.
  • Is, in turn, a dependency of pyharbinger (time series event detection).

Installation

pip install pytspredit

Beta: the current release (0.10.0) is in a testing phase on the way to 1.0.0. Feedback and issues are very welcome.

For a local, editable clone (contributing or running the examples):

git clone https://github.com/cefet-rj-dal/pytspredit.git
cd pytspredit
pip install -e ".[dev,docs]"
pytest

A forecast in a nutshell

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"])

Status

0.10.0 (beta). The port follows the method validated for pydaltoolbox (already on PyPI), with R-vs-Python parity checked at every step on the shared tsd series. Implemented:

  • Core data structures: ts_data (sliding windows), ts_projection, ts_sample, adjust_ts_data, ts_head, datasets.tsd() (numerically identical to R).
  • Regression base: TsReg (MSE / sMAPE / R2 evaluation) and TsRegSW (preprocess + lag map + backend; one-step and iterative multi-step forecasting).
  • Normalizations: TsNormNone, TsNormGminmax, TsNormSwminmax, TsNormDiff, TsNormAn (adaptive; 4 operators) — all invertible.
  • Lag mapping: TsLagmap with 12 strategies (recent, even, geom, acf, pacf, peaks, seasonal, acf/pacf-seasonal, blocks, mutual information, mRMR).
  • Regressors: TsKnn, TsElm, TsRf, TsSvm, TsMlp (sliding-window) and TsArima (univariate ARIMA).
  • Model zoo (0.2.0): TsDeterministic (TsPeriodic, TsPersist), TsDarima and TsWarma (window linear models) — no new dependencies.
  • Augmentation (0.3.0): TsAugNone, TsAugFlip, TsAugStretch, TsAugShrink, TsAugJitter, TsAugWormhole, TsAugAwareness, TsAugAwaresmooth (native) — plug into TsIntegtune's augmentation slot.
  • Filters (0.4.0): TsFilNone/Ma/Ema/Winsor/Recursive/Fft/Smooth/Hp/Gabor (native, R-exact) + TsFilLowess/Ses/Qes/SeasAdj/Spline/Kalman (statsmodels/scipy). Adds scipy as a (lightweight) core dependency.
  • Tuning: TsTune and TsIntegtune (integrated tuning of input size, preprocessing and model hyperparameters).
  • Multivariate (0.5.0): ts_data_mv / adjust_ts_data_mv / ts_mv_spec, the sliding-window orchestrator TsRegswMv, and the singular (aligned) branch TsLmMv (linear regression), TsVar (vector autoregression) and TsArimax (ARIMA with external regressors) — all target-centered. Plus plot_ts_pred / plot_ts_pred_mv (matplotlib), adding matplotlib as a (lightweight) core dependency.
  • Benchmark (0.6.0): the tspredbench dataset collection as Eidolon miniatures — compact, package-native stand-ins (CSV/JSON + manifest.json) carrying the remote URL of the full artifact, numerically identical to R — exposed via datasets.<name>() (20 datasets + tsd); plus TsPredBench, a datasets x models grid harness returning a tidy MSE/sMAPE/R2 table. No new dependency.
  • EMD decomposition filters (0.7.0): TsFilEmd (remove the noisiest IMF) and TsFilRemd (adaptive roughness-based removal) on a native, dependency-free EMD/ EEMD engine (pytspredit.emd, numpy + scipy) — no [emd] extra. The native engine is orders of magnitude faster than the R hht backend and denoises at least as well; it is canonical here (the R package is to be backported to it, dropping hht). CEEMDAN was evaluated and left out (no denoising gain for this use case).
  • Wavelet filter (0.8.0): TsFilWavelet on a native, dependency-free MODWT (pytspredit.wavelet, pure numpy — not even scipy) — no [wavelet] extra. Because the MODWT is a deterministic linear transform, the native engine matches the R wavelets package value-for-value (~5e-6), more faithfully than wrapping PyWavelets. Filter families haar/d4/la8/bl14/c6; fit selects the best by R2. Wavelet thresholding (Donoho-Johnstone) was evaluated and left out (did not improve denoising here).
  • Full datasets (0.9.0): datasets.loadfulldata(name) downloads the complete dataset on demand (Eidolon expansion) — the full data is published as gzip-compressed Python-native files (.csv.gz/.json.gz) and read with urllib + pandas, so it is 0 new dependency (gzipped CSV beat both plain CSV on size and .RData/parquet on size+deps in benchmarking — no rdata/pyarrow/xarray).
  • ARIMA++ (0.10.0): TsArima(auto="cv") — a smarter automatic order selector that fixes two weaknesses of auto.arima: ACF/PACF-driven candidates (seasonal lags enter the search instead of a fixed cap of 5) and selection by horizon-matched rolling-origin cross-validation (out-of-sample accuracy, not the in-sample AICc proxy). On real competition data (NN5) it forecasts ~14% better than the AICc auto. Native, 0 new dependency — the first genuine algorithmic ++ (beyond dependency reduction).

Every class documents its academic references and its R-port fidelity (References: / Porting: in the docstrings), mirroring the roxygen @references and @details of the R package. Thin adapters over scikit-learn / numpy / pandas / statsmodels reproduce the R backends' defaults (e.g. SVM standardizes like e1071). Deferred to the next cycle (see develop/planejamento.md): the 1.0.0 maturity passes (1:1 examples, credit audit, parity matrix). The full tspredit port is complete.

Documentation

License

MIT

Metadata

Release files for pytspredit 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytspredit 0.13.0
File Size Uploaded Provenance Actions
pytspredit-0.13.0.tar.gz 126.4 kB Without provenance Details for pytspredit-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytspredit 0.13.0
File Interpreter ABI Platform Actions
pytspredit-0.13.0-py3-none-any.whl Python 3 none any Details for pytspredit-0.13.0-py3-none-any.whl

Total release size: 262.2 kB

Release files / pytspredit-0.13.0.tar.gz

Download URL pytspredit-0.13.0.tar.gz
Size 126.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7a300e577aab05f7e8657a7dee8d9f4aa09c8cdc3690a651f56e89f73a8b75d7
BLAKE2b-256 checksum
How to use checksums
f829ccc0abefe43e589f80772b3a39c0e69e027243bd650fac88e3257e5ec415
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / pytspredit-0.13.0-py3-none-any.whl

Download URL pytspredit-0.13.0-py3-none-any.whl
Size 135.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ae3b65774832bb3c2c1033e24cd9da42da8d829ef008a0793a45c0d5ca1a1e3
BLAKE2b-256 checksum
How to use checksums
95c311d10817babb56732802346c717105b75b033fff77035315b32a99225ed3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Security for pytspredit 0.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page