pytspredit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytspredit-0.1.0/.gitignore +223 -0
- pytspredit-0.1.0/LICENSE +21 -0
- pytspredit-0.1.0/PKG-INFO +131 -0
- pytspredit-0.1.0/README.md +97 -0
- pytspredit-0.1.0/pyproject.toml +56 -0
- pytspredit-0.1.0/src/pytspredit/__init__.py +66 -0
- pytspredit-0.1.0/src/pytspredit/arima.py +118 -0
- pytspredit-0.1.0/src/pytspredit/augment.py +22 -0
- pytspredit-0.1.0/src/pytspredit/data/tsd.csv +42 -0
- pytspredit-0.1.0/src/pytspredit/datasets.py +27 -0
- pytspredit-0.1.0/src/pytspredit/lagmap.py +301 -0
- pytspredit-0.1.0/src/pytspredit/norm.py +342 -0
- pytspredit-0.1.0/src/pytspredit/regressors.py +189 -0
- pytspredit-0.1.0/src/pytspredit/ts_reg.py +167 -0
- pytspredit-0.1.0/src/pytspredit/tsdata.py +132 -0
- pytspredit-0.1.0/src/pytspredit/tune.py +159 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Conda environments
|
|
163
|
+
conda-meta/
|
|
164
|
+
|
|
165
|
+
# Spyder project settings
|
|
166
|
+
.spyderproject
|
|
167
|
+
.spyproject
|
|
168
|
+
|
|
169
|
+
# Rope project settings
|
|
170
|
+
.ropeproject
|
|
171
|
+
|
|
172
|
+
# mkdocs/Zensical documentation
|
|
173
|
+
/site
|
|
174
|
+
|
|
175
|
+
# mypy
|
|
176
|
+
.mypy_cache/
|
|
177
|
+
.dmypy.json
|
|
178
|
+
dmypy.json
|
|
179
|
+
|
|
180
|
+
# Pyre type checker
|
|
181
|
+
.pyre/
|
|
182
|
+
|
|
183
|
+
# pytype static type analyzer
|
|
184
|
+
.pytype/
|
|
185
|
+
|
|
186
|
+
# Cython debug symbols
|
|
187
|
+
cython_debug/
|
|
188
|
+
|
|
189
|
+
# PyCharm
|
|
190
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
191
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
192
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
193
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
194
|
+
# .idea/
|
|
195
|
+
|
|
196
|
+
# Abstra
|
|
197
|
+
# Abstra is an AI-powered process automation framework.
|
|
198
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
199
|
+
# Learn more at https://abstra.io/docs
|
|
200
|
+
.abstra/
|
|
201
|
+
|
|
202
|
+
# Visual Studio Code
|
|
203
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
204
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
205
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
206
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
207
|
+
# .vscode/
|
|
208
|
+
# Temporary file for partial code execution
|
|
209
|
+
tempCodeRunnerFile.py
|
|
210
|
+
|
|
211
|
+
# Ruff stuff:
|
|
212
|
+
.ruff_cache/
|
|
213
|
+
|
|
214
|
+
# PyPI configuration file
|
|
215
|
+
.pypirc
|
|
216
|
+
|
|
217
|
+
# Marimo
|
|
218
|
+
marimo/_static/
|
|
219
|
+
marimo/_lsp/
|
|
220
|
+
__marimo__/
|
|
221
|
+
|
|
222
|
+
# Streamlit
|
|
223
|
+
.streamlit/secrets.toml
|
pytspredit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Data Analytics Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytspredit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Time series prediction with tunable preprocessing (Python port of the R tspredit framework)
|
|
5
|
+
Project-URL: Homepage, https://github.com/cefet-rj-dal/pytspredit
|
|
6
|
+
Project-URL: Repository, https://github.com/cefet-rj-dal/pytspredit
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/cefet-rj-dal/pytspredit/issues
|
|
8
|
+
Author-email: Eduardo Ogasawara <eogasawara@ieee.org>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: experiment line,forecasting,machine learning,scikit-learn,time series
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: numpy>=1.23
|
|
19
|
+
Requires-Dist: pandas>=1.5
|
|
20
|
+
Requires-Dist: pydaltoolbox>=0.1.0
|
|
21
|
+
Requires-Dist: scikit-learn>=1.2
|
|
22
|
+
Requires-Dist: statsmodels>=0.14
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: build; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
27
|
+
Requires-Dist: twine; extra == 'dev'
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: ipykernel>=6; extra == 'docs'
|
|
30
|
+
Requires-Dist: jupytext>=1.16; extra == 'docs'
|
|
31
|
+
Requires-Dist: nbclient>=0.9; extra == 'docs'
|
|
32
|
+
Requires-Dist: nbconvert>=7; extra == 'docs'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# pytspredit
|
|
36
|
+
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
|
|
39
|
+
Python port of the R [tspredit](https://github.com/cefet-rj-dal/tspredit) — **time series
|
|
40
|
+
prediction with tunable preprocessing**, built on the DAL Toolbox *Experiment Line*.
|
|
41
|
+
|
|
42
|
+
`pytspredit` provides a uniform, extensible interface for time series forecasting:
|
|
43
|
+
sliding-window modeling, normalization, filtering and augmentation, machine-learning and
|
|
44
|
+
statistical regressors, and hyperparameter tuning — reusing the best of the Python
|
|
45
|
+
ecosystem (scikit-learn, numpy, pandas, statsmodels) through thin adapters. Its value is
|
|
46
|
+
**not** reimplementing algorithms, but the rigid, extensible interface that wraps them.
|
|
47
|
+
|
|
48
|
+
It is part of the DAL Python family:
|
|
49
|
+
|
|
50
|
+
- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** — the
|
|
51
|
+
foundation (Python port of the R `daltoolbox`), on PyPI.
|
|
52
|
+
- Is, in turn, a dependency of **pyharbinger** (time series event detection).
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
Once released:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install pytspredit
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For a local, editable clone (contributing or running the examples):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/cefet-rj-dal/pytspredit.git
|
|
66
|
+
cd pytspredit
|
|
67
|
+
pip install -e ".[dev,docs]"
|
|
68
|
+
pytest
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## A forecast in a nutshell
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import pytspredit as ts
|
|
75
|
+
|
|
76
|
+
series = ts.datasets.tsd()["y"] # example series
|
|
77
|
+
windows = ts.ts_data(series, sw=10) # sliding windows: columns t9 ... t0
|
|
78
|
+
samp = ts.ts_sample(windows, test_size=5) # temporal train/test split
|
|
79
|
+
io_train = ts.ts_projection(samp.train) # -> (input X, output t0)
|
|
80
|
+
io_test = ts.ts_projection(samp.test)
|
|
81
|
+
|
|
82
|
+
# a kNN regressor with min-max normalization and PACF-based lag selection
|
|
83
|
+
model = ts.TsKnn(ts.TsNormGminmax(), input_size=4, input_map=ts.TsLagmap("pacf"), k=3)
|
|
84
|
+
model.fit(io_train.input, io_train.output)
|
|
85
|
+
|
|
86
|
+
forecast = model.predict(io_test.input.iloc[[0]], steps_ahead=5) # 5 steps ahead
|
|
87
|
+
print(model.evaluate(io_test.output.to_numpy(), forecast)["metrics"])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Status
|
|
91
|
+
|
|
92
|
+
**v1 feature-complete (pre-release).** The port follows the method validated for
|
|
93
|
+
`pydaltoolbox` (already on PyPI), with **R-vs-Python parity checked at every step** on
|
|
94
|
+
the shared `tsd` series. Implemented:
|
|
95
|
+
|
|
96
|
+
- **Core data structures:** `ts_data` (sliding windows), `ts_projection`, `ts_sample`,
|
|
97
|
+
`adjust_ts_data`, `ts_head`, `datasets.tsd()` (numerically identical to R).
|
|
98
|
+
- **Regression base:** `TsReg` (MSE / sMAPE / R2 evaluation) and `TsRegSW`
|
|
99
|
+
(preprocess + lag map + backend; one-step and iterative multi-step forecasting).
|
|
100
|
+
- **Normalizations:** `TsNormNone`, `TsNormGminmax`, `TsNormSwminmax`, `TsNormDiff`,
|
|
101
|
+
`TsNormAn` (adaptive; 4 operators) — all invertible.
|
|
102
|
+
- **Lag mapping:** `TsLagmap` with 12 strategies (recent, even, geom, acf, pacf, peaks,
|
|
103
|
+
seasonal, acf/pacf-seasonal, blocks, mutual information, mRMR).
|
|
104
|
+
- **Regressors:** `TsKnn`, `TsElm`, `TsRf`, `TsSvm`, `TsMlp` (sliding-window) and
|
|
105
|
+
`TsArima` (univariate ARIMA).
|
|
106
|
+
- **Tuning:** `TsTune` and `TsIntegtune` (integrated tuning of input size,
|
|
107
|
+
preprocessing and model hyperparameters).
|
|
108
|
+
|
|
109
|
+
Thin adapters over scikit-learn / numpy / pandas / statsmodels reproduce the R
|
|
110
|
+
backends' defaults (e.g. SVM standardizes like `e1071`). Deferred to a later release
|
|
111
|
+
(see [develop/planejamento.md](develop/planejamento.md)): the multivariate family
|
|
112
|
+
(`ts_data_mv`, `ts_var`, `ts_arimax`), filters, the full augmentation family, and
|
|
113
|
+
graphics.
|
|
114
|
+
|
|
115
|
+
## Documentation
|
|
116
|
+
|
|
117
|
+
- [Processed examples](examples/) — notebooks executed end to end, with real output
|
|
118
|
+
embedded. Sources live under [notebooks/](notebooks/) (jupytext Markdown), rendered by
|
|
119
|
+
`python tools/build_examples.py`.
|
|
120
|
+
- [develop/planejamento.md](develop/planejamento.md) — migration roadmap (phases, scope, status).
|
|
121
|
+
- [develop/deploy.md](develop/deploy.md) — PyPI publishing guide.
|
|
122
|
+
|
|
123
|
+
## Related DAL projects
|
|
124
|
+
|
|
125
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
|
|
126
|
+
- [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
|
|
127
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# pytspredit
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
Python port of the R [tspredit](https://github.com/cefet-rj-dal/tspredit) — **time series
|
|
6
|
+
prediction with tunable preprocessing**, built on the DAL Toolbox *Experiment Line*.
|
|
7
|
+
|
|
8
|
+
`pytspredit` provides a uniform, extensible interface for time series forecasting:
|
|
9
|
+
sliding-window modeling, normalization, filtering and augmentation, machine-learning and
|
|
10
|
+
statistical regressors, and hyperparameter tuning — reusing the best of the Python
|
|
11
|
+
ecosystem (scikit-learn, numpy, pandas, statsmodels) through thin adapters. Its value is
|
|
12
|
+
**not** reimplementing algorithms, but the rigid, extensible interface that wraps them.
|
|
13
|
+
|
|
14
|
+
It is part of the DAL Python family:
|
|
15
|
+
|
|
16
|
+
- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** — the
|
|
17
|
+
foundation (Python port of the R `daltoolbox`), on PyPI.
|
|
18
|
+
- Is, in turn, a dependency of **pyharbinger** (time series event detection).
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Once released:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pytspredit
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For a local, editable clone (contributing or running the examples):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git clone https://github.com/cefet-rj-dal/pytspredit.git
|
|
32
|
+
cd pytspredit
|
|
33
|
+
pip install -e ".[dev,docs]"
|
|
34
|
+
pytest
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## A forecast in a nutshell
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import pytspredit as ts
|
|
41
|
+
|
|
42
|
+
series = ts.datasets.tsd()["y"] # example series
|
|
43
|
+
windows = ts.ts_data(series, sw=10) # sliding windows: columns t9 ... t0
|
|
44
|
+
samp = ts.ts_sample(windows, test_size=5) # temporal train/test split
|
|
45
|
+
io_train = ts.ts_projection(samp.train) # -> (input X, output t0)
|
|
46
|
+
io_test = ts.ts_projection(samp.test)
|
|
47
|
+
|
|
48
|
+
# a kNN regressor with min-max normalization and PACF-based lag selection
|
|
49
|
+
model = ts.TsKnn(ts.TsNormGminmax(), input_size=4, input_map=ts.TsLagmap("pacf"), k=3)
|
|
50
|
+
model.fit(io_train.input, io_train.output)
|
|
51
|
+
|
|
52
|
+
forecast = model.predict(io_test.input.iloc[[0]], steps_ahead=5) # 5 steps ahead
|
|
53
|
+
print(model.evaluate(io_test.output.to_numpy(), forecast)["metrics"])
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Status
|
|
57
|
+
|
|
58
|
+
**v1 feature-complete (pre-release).** The port follows the method validated for
|
|
59
|
+
`pydaltoolbox` (already on PyPI), with **R-vs-Python parity checked at every step** on
|
|
60
|
+
the shared `tsd` series. Implemented:
|
|
61
|
+
|
|
62
|
+
- **Core data structures:** `ts_data` (sliding windows), `ts_projection`, `ts_sample`,
|
|
63
|
+
`adjust_ts_data`, `ts_head`, `datasets.tsd()` (numerically identical to R).
|
|
64
|
+
- **Regression base:** `TsReg` (MSE / sMAPE / R2 evaluation) and `TsRegSW`
|
|
65
|
+
(preprocess + lag map + backend; one-step and iterative multi-step forecasting).
|
|
66
|
+
- **Normalizations:** `TsNormNone`, `TsNormGminmax`, `TsNormSwminmax`, `TsNormDiff`,
|
|
67
|
+
`TsNormAn` (adaptive; 4 operators) — all invertible.
|
|
68
|
+
- **Lag mapping:** `TsLagmap` with 12 strategies (recent, even, geom, acf, pacf, peaks,
|
|
69
|
+
seasonal, acf/pacf-seasonal, blocks, mutual information, mRMR).
|
|
70
|
+
- **Regressors:** `TsKnn`, `TsElm`, `TsRf`, `TsSvm`, `TsMlp` (sliding-window) and
|
|
71
|
+
`TsArima` (univariate ARIMA).
|
|
72
|
+
- **Tuning:** `TsTune` and `TsIntegtune` (integrated tuning of input size,
|
|
73
|
+
preprocessing and model hyperparameters).
|
|
74
|
+
|
|
75
|
+
Thin adapters over scikit-learn / numpy / pandas / statsmodels reproduce the R
|
|
76
|
+
backends' defaults (e.g. SVM standardizes like `e1071`). Deferred to a later release
|
|
77
|
+
(see [develop/planejamento.md](develop/planejamento.md)): the multivariate family
|
|
78
|
+
(`ts_data_mv`, `ts_var`, `ts_arimax`), filters, the full augmentation family, and
|
|
79
|
+
graphics.
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [Processed examples](examples/) — notebooks executed end to end, with real output
|
|
84
|
+
embedded. Sources live under [notebooks/](notebooks/) (jupytext Markdown), rendered by
|
|
85
|
+
`python tools/build_examples.py`.
|
|
86
|
+
- [develop/planejamento.md](develop/planejamento.md) — migration roadmap (phases, scope, status).
|
|
87
|
+
- [develop/deploy.md](develop/deploy.md) — PyPI publishing guide.
|
|
88
|
+
|
|
89
|
+
## Related DAL projects
|
|
90
|
+
|
|
91
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
|
|
92
|
+
- [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
|
|
93
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pytspredit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Time series prediction with tunable preprocessing (Python port of the R tspredit framework)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Eduardo Ogasawara", email = "eogasawara@ieee.org" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["time series", "forecasting", "machine learning", "experiment line", "scikit-learn"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"numpy>=1.23",
|
|
25
|
+
"pandas>=1.5",
|
|
26
|
+
"scikit-learn>=1.2",
|
|
27
|
+
"statsmodels>=0.14",
|
|
28
|
+
"pydaltoolbox>=0.1.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = ["pytest>=7", "ruff>=0.1", "build", "twine"]
|
|
33
|
+
docs = ["jupytext>=1.16", "nbconvert>=7", "nbclient>=0.9", "ipykernel>=6"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/cefet-rj-dal/pytspredit"
|
|
37
|
+
Repository = "https://github.com/cefet-rj-dal/pytspredit"
|
|
38
|
+
"Bug Tracker" = "https://github.com/cefet-rj-dal/pytspredit/issues"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/pytspredit"]
|
|
42
|
+
|
|
43
|
+
# The published source distribution ships only the package and essential metadata.
|
|
44
|
+
# Development-only material (develop/, notebooks/, examples/, tests/, tools/) is kept
|
|
45
|
+
# out of what users install.
|
|
46
|
+
[tool.hatch.build.targets.sdist]
|
|
47
|
+
include = ["src/pytspredit", "README.md", "LICENSE"]
|
|
48
|
+
exclude = ["develop", "notebooks", "examples", "tests", "tools"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
|
52
|
+
addopts = "-q"
|
|
53
|
+
|
|
54
|
+
[tool.ruff]
|
|
55
|
+
line-length = 100
|
|
56
|
+
target-version = "py39"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""pytspredit -- Time series prediction with tunable preprocessing.
|
|
2
|
+
|
|
3
|
+
Python port of the R ``tspredit`` framework, built on top of ``pydaltoolbox``
|
|
4
|
+
(the Experiment Line foundation). It provides a uniform, extensible interface for
|
|
5
|
+
time series forecasting: sliding-window modeling, normalization, filtering,
|
|
6
|
+
augmentation, machine-learning and statistical regressors, and tuning -- wrapping
|
|
7
|
+
scikit-learn / numpy / pandas / statsmodels with thin adapters.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from . import datasets
|
|
12
|
+
from .arima import TsArima
|
|
13
|
+
from .augment import TsAugNone
|
|
14
|
+
from .lagmap import TsLagmap
|
|
15
|
+
from .norm import (
|
|
16
|
+
TsNormAn,
|
|
17
|
+
TsNormDiff,
|
|
18
|
+
TsNormGminmax,
|
|
19
|
+
TsNormNone,
|
|
20
|
+
TsNormSwminmax,
|
|
21
|
+
)
|
|
22
|
+
from .regressors import TsElm, TsKnn, TsMlp, TsRf, TsSvm
|
|
23
|
+
from .ts_reg import TsReg, TsRegSW, mse_ts, r2_ts, smape_ts
|
|
24
|
+
from .tsdata import (
|
|
25
|
+
TsProjection,
|
|
26
|
+
TsSample,
|
|
27
|
+
adjust_ts_data,
|
|
28
|
+
ts_data,
|
|
29
|
+
ts_head,
|
|
30
|
+
ts_projection,
|
|
31
|
+
ts_sample,
|
|
32
|
+
)
|
|
33
|
+
from .tune import TsIntegtune, TsTune
|
|
34
|
+
|
|
35
|
+
__version__ = "0.1.0"
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"TsArima",
|
|
39
|
+
"TsAugNone",
|
|
40
|
+
"TsElm",
|
|
41
|
+
"TsIntegtune",
|
|
42
|
+
"TsKnn",
|
|
43
|
+
"TsLagmap",
|
|
44
|
+
"TsMlp",
|
|
45
|
+
"TsNormAn",
|
|
46
|
+
"TsNormDiff",
|
|
47
|
+
"TsNormGminmax",
|
|
48
|
+
"TsNormNone",
|
|
49
|
+
"TsNormSwminmax",
|
|
50
|
+
"TsProjection",
|
|
51
|
+
"TsReg",
|
|
52
|
+
"TsRegSW",
|
|
53
|
+
"TsRf",
|
|
54
|
+
"TsSample",
|
|
55
|
+
"TsSvm",
|
|
56
|
+
"TsTune",
|
|
57
|
+
"adjust_ts_data",
|
|
58
|
+
"datasets",
|
|
59
|
+
"mse_ts",
|
|
60
|
+
"r2_ts",
|
|
61
|
+
"smape_ts",
|
|
62
|
+
"ts_data",
|
|
63
|
+
"ts_head",
|
|
64
|
+
"ts_projection",
|
|
65
|
+
"ts_sample",
|
|
66
|
+
]
|